QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117890 | #6680. Heap | hos_lyric | RE | 1ms | 3428kb | C++14 | 2.3kb | 2023-07-02 12:56:34 | 2023-07-02 12:57:02 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
int N;
vector<int> V;
vector<int> A;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &N);
V.resize(N + 1); for (int i = 1; i <= N; ++i) scanf("%d", &V[i]);
A.resize(N + 1); for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
auto as = A;
string ans(N, '?');
int jsLen;
int js[110];
for (int i = N; i >= 1; --i) {
jsLen = 0;
for (int j = i; ; j >>= 1) {
js[jsLen++] = j;
if (as[j] == V[i]) {
break;
}
}
bool can[2] = {true, true};
for (int k = jsLen - 1; --k >= 0; ) {
swap(as[js[k]], as[js[k + 1]]);
if (as[js[k + 1]] <= as[js[k]]) can[0] = false;
if (as[js[k + 1]] >= as[js[k]]) can[1] = false;
}
if (can[0]) {
ans[i - 1] = '0';
} else if (can[1]) {
ans[i - 1] = '1';
} else {
ans = "Impossible";
break;
}
}
puts(ans.c_str());
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3428kb
input:
3 4 2 3 1 4 4 1 3 2 5 4 5 1 2 3 3 4 1 5 2 3 1 1 2 2 1 1
output:
0101 Impossible 001
result:
ok 3 lines
Test #2:
score: -100
Runtime Error
input:
1118 77 210555 375330 669075 785279 194474 310626 830710 886719 102133 426324 41900 971872 167203 702222 230534 112350 673156 358623 886831 72864 818751 367894 842740 531878 818794 131219 412128 104469 70427 658494 72060 768735 915294 161365 91671 451974 121863 498890 408674 670274 875754 967228 518...