QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#132321 | #5665. AA Country and King Dreamoon | willow# | WA | 27ms | 10024kb | C++14 | 2.2kb | 2023-07-29 15:42:27 | 2023-07-29 15:42:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 5;
int T, n, vis[maxn], seq[maxn], lef[maxn], rig[maxn], totl, totr, lim;
int main() {
for(scanf("%d", &T); T --; ) {
scanf("%d", &n);
for(int i = 1; i <= n + 1; ++ i) {
vis[i] = 0;
}
for(int i = 1; i <= 2 * n - 1; ++ i) {
scanf("%d", &seq[i]);
vis[seq[i]] = 1;
}
if(!seq[1] && !seq[2 * n - 1]) {
seq[1] = seq[2 * n - 1] = 1;
vis[1] = 1;
}
else if(!seq[1])
seq[1] = seq[2 * n - 1];
else if(!seq[2 * n - 1])
seq[2 * n - 1] = seq[1];
int l = 1, r = 2 * n - 1, beg = 1;
totl = totr = 0;
while(seq[l]) {
if(totl > 1 && lef[totl - 1] == seq[l])
-- totl;
else
lef[++ totl] = seq[l];
++ l;
}
while(seq[r]) {
if(totr > 1 && rig[totr - 1] == seq[r])
-- totr;
else
rig[++ totr] = seq[r];
-- r;
}
for(lim = 1; lef[lim] == rig[lim] && lim <= min(totl, totr); ++ lim);
-- lim;
for(beg = 1; vis[beg]; ++ beg);
// int deb = 0;
// while(++ deb <= 100) {
// cerr << beg << " " << totl << " " << totr << " " << lim << endl;
// cerr << "lef: ";
// for(int i = 1; i <= totl; ++ i)
// cerr << lef[i] << " ";
// cerr << "rig: ";
// for(int i = 1; i <= totr; ++ i)
// cerr << rig[i] << " ";
// cerr << endl;
while(1) {
if(beg == n + 1) {
if(totl >= totr) {
while(totl > 1 && !seq[l])
seq[l ++] = lef[-- totl];
}
else {
while(totr > 1 && !seq[r])
seq[r --] = rig[-- totr];
}
break;
}
if(totl > lim) {
if(beg < lef[totl - 1]) {
seq[l ++] = beg;
lef[++ totl] = beg;
vis[beg] = 1;
while(vis[beg])
++ beg;
}
else {
seq[l ++] = lef[totl - 1];
-- totl;
}
}
else {
if(totr > lim) {
if(rig[lim + 1] < beg) {
seq[l ++] = rig[lim + 1];
lef[++ totl] = rig[lim + 1];
++ lim;
}
else {
seq[l ++] = beg;
lef[++ totl] = beg;
vis[beg] = 1;
while(vis[beg])
++ beg;
}
}
else {
seq[l ++] = beg;
lef[++ totl] = beg;
vis[beg] = 1;
while(vis[beg])
++ beg;
}
}
}
for(int i = 1; i <= 2 * n - 1; ++ i)
printf("%d ", seq[i]);
puts("");
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9856kb
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
Wrong Answer
time: 27ms
memory: 10024kb
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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