QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#320777#5665. AA Country and King Dreamoonushg8877WA 40ms3724kbC++201.6kb2024-02-03 21:15:292024-02-03 21:15:31

Judging History

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

  • [2024-02-03 21:15:31]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:3724kb
  • [2024-02-03 21:15:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=3e5+5;
int n,a[MAXN<<1];bool vis[MAXN];
int pathl[MAXN],topl,pathr[MAXN],topr,path[MAXN],l,r;
bool full(){
	for(int i=1;i<=2*n-1;i++) if(!a[i]) return false;
	return true;
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) vis[i]=false;
	for(int i=1;i<=2*n-1;i++) cin>>a[i];
	a[1]=a[2*n-1]=1;
	if(full()){
		for(int i=1;i<=2*n-1;i++) cout<<a[i]<<" \n"[i==2*n-1];
		return;
	} 
	for(int i=1;i<=n;i++) vis[a[i]]=true;
	priority_queue<int,vector<int>,greater<int> > q;
	for(int i=1;i<=n;i++) if(!vis[i]) q.push(i);
	q.push(1e9);
	pathl[1]=pathr[1]=topl=topr=1;
	l=1,r=2*n-1;
	while(a[l+1]){
		if(a[l+1]==pathl[topl-1]) topl--;
		else pathl[++topl]=a[l+1];
		l++;
	}
	while(a[r-1]){
		if(a[r-1]==pathr[topr-1]) topr--;
		else pathr[++topr]=a[r-1];
		r--;
	}
	pathl[topl+1]=-1;pathr[topr+1]=-2;
	deque<int> path;
	for(int i=1;i<=topl;i++) if(pathl[i+1]!=pathr[i+1]){
		for(int j=topl;j>=i;j--) path.push_back(pathl[j]);
		for(int j=i+1;j<=topr;j++) path.push_back(pathr[j]);
		break;
	}
	path.push_back(1e9);
	auto front_next=[&](deque<int> &q){
		int x=q.front();q.pop_front();
		int y=q.front();q.push_front(x);
		return y;
	};
	for(int i=l+1;i<r;i++){
		if(front_next(path)>q.top()){
			path.push_front(q.top());
			a[i]=q.top();q.pop();
		}else{
			a[i]=front_next(path);path.pop_front();
		}
	}
	for(int i=1;i<=2*n-1;i++) cout<<a[i]<<" \n"[i==2*n-1];
	
}
int main(){
	ios::sync_with_stdio(false);
	int _;cin>>_;
	while(_--) solve();
}

詳細信息

Test #1:

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

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: 40ms
memory: 3700kb

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

result:

wrong answer 24th lines differ - expected: '1 2 3 2 1', found: '1 2 2 2 1'