QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#184455 | #5665. AA Country and King Dreamoon | ucup-team1508# | WA | 0ms | 5588kb | C++14 | 1.7kb | 2023-09-20 19:33:11 | 2023-09-20 19:33:16 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5 + 10;
int n, a[N], fa[N], vst[N];
void sol() {
cin >> n;
F(i, 1, 2 * n - 1) cin >> a[i];
a[1] = a[2 * n - 1] = 1;
F(i, 1, n) fa[i] = vst[i] = 0;
vst[1] = 3;
int pos = 0;
F(i, 2, 2 * n - 1) {
if(a[i] == 0) {
pos = i;
break;
}
if(! vst[a[i]]) vst[a[i]] = 1, fa[a[i]] = a[i - 1];
else if(fa[a[i - 1]] == a[i]) vst[a[i - 1]] = 3;
}
Fd(i, 2 * n - 2, 2) {
if(a[i] == 0) break;
if(! vst[a[i]]) vst[a[i]] = 2, fa[a[i]] = a[i + 1];
else if(fa[a[i + 1]] == a[i]) vst[a[i + 1]] = 3;
}
// F(i, 1, n) cout << fa[i] << " \n" [i == n];
// F(i, 1, n) cout << vst[i] << " \n" [i == n];
priority_queue<int, vector<int>, greater<int> > q;
F(i, 1, n) if(! vst[i] || vst[i] == 2) q.push(i);
F(i, pos, 2 * n - 1) {
if(a[i]) break;
int x = 0, y = fa[a[i - 1]];
while(q.size() && (vst[q.top()] == 1 || vst[q.top()] == 3)) q.pop();
if(q.size()) x = q.top();
if(x && (vst[a[i - 1]] == 2 || vst[a[i - 1]] == 3 || x < y)) {
a[i] = q.top();
fa[a[i]] = a[i - 1];
if(vst[a[i]] == 2) vst[a[i]] = 3;
else vst[a[i]] = 1;
q.pop();
continue;
}
vst[a[i - 1]] = 3;
a[i] = fa[a[i - 1]];
}
F(i, 1, 2 * n - 1) cout << a[i] << " \n" [i == 2 * n - 1];
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while(t --) sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5588kb
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 1 2 1 5 1 1 2 3 2 1 2 1 5 1 1 2 1 3 1 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:
wrong answer 1st lines differ - expected: '1 2 3 2 4 2 1 5 1', found: '1 2 3 2 1 2 1 5 1'