QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#284358#5687. 速战速决simonG#WA 27ms8344kbC++141.4kb2023-12-16 13:18:252023-12-16 13:18:25

Judging History

This is the latest submission verdict.

  • [2023-12-16 13:18:25]
  • Judged
  • Verdict: WA
  • Time: 27ms
  • Memory: 8344kb
  • [2023-12-16 13:18:25]
  • Submitted

answer

#include<bits/stdc++.h>
#define il inline 
#define re register
#define ll long long
#define pb push_back
using namespace std;
const int N=1e6+10;
#define gc() getchar()
il int rd(){
	int x=0,f=1;
	char ch=gc();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=gc();
	return x*f;
}
int n;
int a[N],cnt[N],vis[N];
vector<int>q;
int insert(int x){
	int p=rand()%n+1;
	while(p==q.front()||!cnt[p]||!p==x)p=rand()%n+1;
	--cnt[p],vis[p]=1,q.pb(p);
	return p;
}
void delet(){
	++cnt[q.back()],vis[q.back()]=0,q.pop_back();
}
void Main(){
	n=rd();
	for(int i=1; i<=n; ++i)a[i]=rd();
	srand(time(0));
	if(n==1){
		puts("-1");
		return;
	}
	for(int i=1; i<=n; ++i)++cnt[a[i]];
	for(int i=1; i<=n; ++i)cnt[i]=2-cnt[i];
	for(int i=1; i<=n; ++i){
		if(cnt[i]==2){
			printf("%d\n",n);
			printf("%d ",i);vis[i]=1;q.pb(i),--cnt[i];
			q.pb(a[1]),vis[a[1]]=1;
			for(int j=2; j<=n; ++j){
				if(vis[a[j]]){
					printf("%d ",q.front());
					while(!q.empty())delet();
				}else{
					printf("%d ",insert(a[j]));
				}
				q.pb(a[j]),vis[a[j]]=1;
			}
			exit(0);
		}
	}
	printf("%d\n",n+2);
	printf("%d ",a[1]);
	for(int i=2; i<=n; ++i)printf("%d ",a[i]);
	printf("%d %d",a[n],a[n]);
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 27ms
memory: 8344kb

input:

249665
195633 37425 205189 128330 159707 98406 111454 30346 158516 121742 107964 50039 201395 16843 182333 60177 195166 188257 172666 71779 157060 237654 123572 145065 57507 152240 187931 5706 191077 214174 70950 71272 172767 61529 85258 74139 44633 181186 223348 222711 19237 239887 20487 84130 1392...

output:

249665
2 83268 177068 170930 43163 116996 211577 129901 192369 170537 109289 34439 58386 134269 230166 29472 75897 201240 105984 75539 12654 244931 44312 73382 215246 127579 21527 170742 2797 50977 38991 45282 114620 179550 229802 175590 229645 9608 103007 4616 220186 108072 90873 68627 50370 223840...

result:

FAIL Game continues but you do not move