QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732709#5665. AA Country and King DreamoonAshbourneWA 32ms7688kbC++231.6kb2024-11-10 15:39:232024-11-10 15:39:28

Judging History

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

  • [2024-11-10 15:39:28]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:7688kb
  • [2024-11-10 15:39:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int a[N], Ton[N], fa[N];
void solve(){
	int n, l = 0, r = n;
	cin >> n;
	vector<int> vis(n + 100);
	for(int i = 1; i <= n; ++ i) Ton[i] = 0, fa[i] = 0;
	// vector<int> a(2 * n + 1);
	a[0] = 1e14; a[2 * n] = 1e14; 
	for(int i = 1; i <= 2 * n - 1; ++ i) cin >> a[i];
	for(int i = 1; i <= 2 * n - 1; ++ i){
	    vis[a[i]] = 1;
		if(a[i - 1] && !a[i]) l = i;
		if(!a[i] && a[i + 1]) r = i;
	}
	int lx, rx;
	vis[n + 1] = 1;
	for(int i = 1; i <= n; ++ i){
		if(vis[i - 1] && !vis[i]) lx = i;
		if(!vis[i] && vis[i + 1]) rx = i;
	}
	// cout << l << " " << r << endl;
	for(int i = r + 1; i <= 2 * n - 1; ++ i) Ton[a[i]]++;
	if(l == 1 && r == 2 * n - 1){
		for(int i = 1; i <= 2 * n - 1; ++ i){
			if(i % 2 == 1) a[i] = 1;
			else a[i] = i / 2 + 1;
			cout << a[i] << " ";
 		}
 		cout << endl;
		return;
	}
	if(l == 1){
		a[1] = a[n];
		l++;
	}
	// cout << l << " " << r << endl;
	fa[a[1]] = 1e14;
	for(int i = 2; i <= l - 1; ++ i){
		if(!fa[a[i]]) fa[a[i]] = a[i - 1];
	}
	// cout << fa[3] << endl; 
	for(int i = l; i <= r; ++ i){
		int rd = fa[a[i - 1]];
		// cout << rd << endl;
		bool flag = 1;
		if(rd == 1e14 || Ton[a[i - 1]]) flag = 0;
		// cout << flag  << endl;
		if(flag && (rd < lx || lx > rx)){
			a[i] = rd;
		}else{
			a[i] = lx++;
			fa[a[i]] = a[i - 1];
		}
	}
	for(int i = 1; i <= 2 * n - 1; ++i ){
		cout << a[i] << " ";
	}
	cout << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	int T;
	cin >> T;
	while(T--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7688kb

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: 32ms
memory: 7624kb

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:

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

result:

wrong answer 1st lines differ - expected: '1 2 1', found: '2 2 1 '