QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#284406 | #5689. 喵了个喵 II | simonG# | WA | 4ms | 7960kb | C++14 | 1.4kb | 2023-12-16 13:25:30 | 2023-12-16 13:25:31 |
Judging History
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[n]);
for(int i=1; i<n; ++i)printf("%d ",a[i]);
printf("%d %d",a[1],a[1]);
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=1;
while(T--)Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 7960kb
input:
50000 12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30112 31...
output:
50002 49525 12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30...
result:
wrong answer Incorrect