QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120578 | #6680. Heap | Denisov | WA | 92ms | 4408kb | C++20 | 3.3kb | 2023-07-06 22:01:12 | 2023-07-06 22:01:14 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef LOCAL
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
inline bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
inline bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef LOCAL
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif // LOCAL
const int max_n = -1, inf = 1000111222;
inline void test_case () {
int n;
cin >> n;
vector <int> a(n + 1), v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <int> ans(n + 1);
for (int i = n; i > 0; i--) {
int x = i;
int cnt[2] = {};
vector <int> path;
while (x > 1 && a[x] != v[i]) {
++cnt[a[x] < v[i]];
path.pb(x);
x /= 2;
}
if (a[x] != v[i]) {
cout << "Impossible\n";
return;
}
if (x > 1 && a[x / 2] != v[i]) {
++cnt[a[x / 2] < v[i]];
}
if (cnt[0] && cnt[1]) {
cout << "Impossible\n";
return;
}
if (!cnt[0] && !cnt[1]) {
continue;
}
int must = 0;
if (cnt[1]) {
must = 1;
}
reverse(all(path));
for (int ver : path) {
swap(a[ver], a[x]);
LOG(x, ver);
x = ver;
// cout << ver << ' ';
}
LOG("end");
// cout << '\n';
ans[i] = must;
// for (int j = 1; j <= n; j++) {
// cout << a[j] << ' ';
// }
// cout << '\n';
}
for (int i = 1; i <= n; i++) {
cout << ans[i];
}
cout << '\n';
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
for (int test = 1; test <= t; test++) {
test_case();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
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: 92ms
memory: 4408kb
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 00 Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible 0 Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossible Impossi...
result:
wrong answer 1st lines differ - expected: '000101111110101000001010001010...0101001001001000001100111100010', found: 'Impossible'