QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123944 | #6680. Heap | batrr# | WA | 120ms | 5928kb | C++17 | 2.9kb | 2023-07-14 00:55:27 | 2023-07-14 00:55:29 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
int n, a[N], h[N], H[N];
bool ans[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> h[i];
for (int i = 1; i <= n; i++)
H[i] = h[i];
for (int i = n; i >= 1; i--) {
int j = i;
bool found = false;
int mn = 2e9, mx = -2e9;
while (j >= 1) {
if (a[i] == h[j]) {
found = true;
break;
}
mn = min(mn, h[j]);
mx = max(mx, h[j]);
j /= 2;
}
if (!found) {
cout << "Impossible\n";
return;
}
if ((j > 1 && h[j / 2] < a[i]) || a[i] < mn) {
ans[i] = 0;
int q = i;
int lst = -1;
while (true) {
swap(h[q], lst);
if (q == j)
break;
q /= 2;
}
continue;
}
if ((j > 1 && h[j / 2] > a[i]) || a[i] > mx) {
ans[i] = 1;
int q = i;
int lst = -1;
while (true) {
swap(h[q], lst);
if (q == j)
break;
q /= 2;
}
continue;
}
cout << "Impossible\n";
return;
}
for (int i = 1; i <= n; i++) {
h[i] = a[i];
int j = i;
while (j > 1) {
if (ans[i] == false && h[j / 2] <= h[j])
break;
if (ans[i] == true && h[j / 2] >= h[j])
break;
swap(h[j], h[j / 2]);
j /= 2;
}
}
for (int i = 1; i <= n; i++)
if (h[i] != H[i]) {
cout << "Impossible\n";
return;
}
for (int i = 1; i <= n; i++)
cout << ans[i];
cout << "\n";
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5464kb
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
Wrong Answer
time: 120ms
memory: 5928kb
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...
output:
Impossible Impossible Impossible 0 Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible 0 Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible...
result:
wrong answer 1st lines differ - expected: '000101111110101000001010001010...0101001001001000001100111100010', found: 'Impossible'