QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85251 | #5687. 速战速决 | liaopengfei | WA | 219ms | 19224kb | C++17 | 1.2kb | 2023-03-07 14:17:15 | 2023-03-07 14:17:17 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int N = 6e5 + 15;
set<int> ac;
set<int>::iterator it;
int n,now[N],b[N],a[N],cur,ans[N],bf[N],c[N];
void doit(int x){
int bt=0;
For(i,x,n+x-1){
if(now[b[i]]==1||bt==0){
ans[i]=cur;
if(bt==0) bf[++bt]=cur,now[cur]=1;
else{
while(bf[bt]!=cur){
ac.insert(bf[bt]);
now[bf[bt--]]=0;
}
now[cur]=0,--bt;
}
}else{
it=ac.begin();
while((*it)==cur) it++;
int t=*it;
ans[i]=t;
if(now[t]){
while(bf[bt]!=t){
ac.insert(bf[bt--]);
now[bf[bt--]]=0;
}
now[t]=0,--bt;
}else bf[++bt]=t;
}
bf[++bt]=b[i];
now[b[i]]=1;
if(bt==1) cur=b[i];
}
For(i,x,n+x-1) printf("%d ",ans[i]);
}
int main(){
scanf("%d",&n);
bool qq=0;
For(i,1,n){
scanf("%d",&b[i]);
c[b[i]]++;
if(c[b[i]]>1) qq=1;
}
For(i,1,n){
if(c[i]==0) cur=i;
if(c[i]<=1) ac.insert(i);
}
if(qq){
printf("%d\n",n);
doit(1);
}else{
if(n==1){
printf("-1\n");
return 0;
}
printf("%d\n%d %d ",n+2,b[2],b[1]);
b[n+1]=b[n+2]=b[2]; cur=b[1]; ac.erase(b[2]);
doit(3);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 219ms
memory: 19224kb
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 249660 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
FAIL card does not exist