QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111798 | #5665. AA Country and King Dreamoon | xaphoenix# | RE | 0ms | 9612kb | C++17 | 2.2kb | 2023-06-08 20:34:28 | 2023-06-08 20:34:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC ch[k][0]
#define RC ch[k][1]
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const int N = 600010;
const int M = 610000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const double eps = 1e-9;
int n, a[N], t[N], dep[N];
int fa[N];
vector<int> v1, v2;
void solve() {
cin >> n;
int tot = 2 * n - 1;
repn(i, 1, n) {
dep[i] = 0; fa[i] = 0;
}
repn(i, 1, tot) cin >> a[i];
a[1] = 1; a[tot] = 1;
int l, r, pl;
int d = 0;
repn(i, 1, n) t[i] = 0;
repn(i, 1, tot) {
if (!a[i]) {
l = a[i - 1]; pl = i;
break;
}
if (t[a[i]]) d --;
else {
fa[a[i]] = a[i - 1];
d ++; t[a[i]] = 1;
}
dep[a[i]] = d;
}
d = 0;
repn(i, 1, n) t[i] = 0;
pern(i, 1, tot) {
if (!a[i]) {
r = a[i + 1];
break;
}
if (t[a[i]]) d --;
else {
fa[a[i]] = a[i + 1];
d ++; t[a[i]] = 1;
}
dep[a[i]] = d;
}
v1.clear(); v2.clear();
if (l != r) {
v2.pb(r);
while (l != r) {
if (dep[l] >= dep[r]) {
l = fa[l]; if (l != r) v1.pb(l);
}
else {
r = fa[r]; if (l != r) v2.pb(r);
}
}
per(i, 0, v2.size()) v1.pb(v2[i]);
}
int mn = n + 1;
repn(i, 1, n) {
if (!dep[i]) {
mn = i; break;
}
}
int val = l;
bool yes = false;
for (auto x : v1) {
if (x > mn && !yes) {
repn(i, 1, n) {
if (dep[i]) continue;
a[pl ++] = i; a[pl ++] = val;
}
yes = true;
}
a[pl ++] = x;
val = x;
}
if (!yes){
repn(i, 1, n) {
if (dep[i]) continue;
a[pl ++] = i; a[pl ++] = val;
}
}
repn(i, 1, tot) {
cout << a[i];
if (i < tot) cout << " ";
else cout << "\n";
}
}
int main()
{
IO;
int T;
cin >> T;
repn(i, 1, T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9612kb
input:
9 5 1 2 3 2 0 2 1 5 1 5 1 2 3 0 0 2 1 5 1 5 1 2 0 0 0 2 1 5 1 5 1 2 0 0 0 0 1 5 1 5 1 0 0 0 0 0 1 5 1 5 1 0 0 0 0 0 0 5 1 5 1 0 0 0 0 0 0 0 1 5 1 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0
output:
1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1
result:
ok 9 lines
Test #2:
score: -100
Runtime Error
input:
28668 2 0 2 1 2 0 0 1 2 0 0 0 2 1 0 1 2 1 0 0 2 1 2 0 3 0 2 1 3 1 3 0 0 1 3 1 3 0 0 0 3 1 3 0 0 0 0 1 3 0 0 0 0 0 3 1 0 1 3 1 3 1 0 0 3 1 3 1 0 0 0 1 3 1 0 0 0 0 3 1 2 0 3 1 3 1 2 0 0 1 3 1 2 0 0 0 3 1 2 1 0 1 3 1 2 1 0 0 3 1 2 1 3 0 3 0 2 3 2 1 3 0 0 3 2 1 3 0 0 0 2 1 3 1 0 3 2 1 3 1 0 0 2 1 3 1 2 ...