QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84325 | #5665. AA Country and King Dreamoon | HOLIC | WA | 2ms | 3296kb | C++20 | 2.2kb | 2023-03-06 10:41:25 | 2023-03-06 10:42:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1009;
int n, a[N], vis[N], fa[N], dep[N];
void work() {
cin >> n;
for(int i = 1; i < 2 * n; i ++) cin >> a[i];
//a[1] = a[2 * n - 1] = 1;
int l = 2 * n, r = 0;
for(int i = 1; i < 2 * n; i ++) {
if(a[i] == 0) {
l = min(l, i);
r = max(r, i);
}
}
for(int i = 1; i <= n; i ++) dep[i] = vis[i] = fa[i] = 0;
int now = 0;
for(int i = 1; i < l; i ++) {
if(vis[a[i]]) now = a[i];
else fa[a[i]] = now, dep[a[i]] = dep[now] + 1, now = a[i];
vis[a[i]] = 1;
}
set<int> s;
for(int i = 1; i <= n; i ++) s.insert(i), vis[i] = 0;
int Now = 0;
for(int i = 2 * n - 1; i > r; i --) {
if(vis[a[i]]) Now = a[i];
else fa[a[i]] = Now, dep[a[i]] = dep[Now] + 1, Now = a[i];
vis[a[i]] = 1;
}
for(int i = 1; i <= n; i ++)
s.erase(a[i]);
int num = r - l + 1;
vector<int> a1, a2;
int x = now, X = Now;
//cout << x << " " << X << " " << dep[x] << " " << dep[X] << endl;
while(x != X) {
if(dep[x] >= dep[X]) {
x = fa[x];
if(x != X) a2.push_back(x);
}
else {
X = fa[X];
if(x != X) a2.push_back(X);
}
//cout << x << " " << X << endl;
}
if(now != Now)a2.push_back(Now);
reverse(a2.begin(), a2.end());
for(auto v : a2) a1.push_back(v);
//for(auto v : a1) cout << v << " ";
//cout << endl;
reverse(a1.begin(), a1.end());
for(int i = 1; i < l; i ++) cout << a[i] << " ";
for(int i = l; i <= r; i ++) {
if(!s.empty() && (a1.empty() || *s.begin() < a1.back())) {
if(now)a1.push_back(now);
now = *s.begin();
s.erase(s.begin());
cout << now << " ";
} else {
cout << a1.back() << " ";
now = a1.back();
a1.pop_back();
}
}
for(int i = r + 1; i < 2 * n; i ++) cout << a[i] << " ";
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int Case;
cin >> Case;
while(Case --) work();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3296kb
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 0 2 3 2 4 2 5 2 1 2 1 3 1 4 1 5 1
result:
wrong answer 8th lines differ - expected: '1 2 1 3 1 4 1 5 1', found: '1 0 2 3 2 4 2 5 2 '