QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132321#5665. AA Country and King Dreamoonwillow#WA 27ms10024kbC++142.2kb2023-07-29 15:42:272023-07-29 15:42:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-29 15:42:28]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:10024kb
  • [2023-07-29 15:42:27]
  • 提交

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 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 1234th lines differ - expected: '1 2 3 2 1 4 5 4 1', found: '1 2 3 2 1 0 5 4 1 '