Submission #521007

#TimeUsernameProblemLanguageResultExecution timeMemory
521007lucriDEL13 (info1cup18_del13)C++17
0 / 100
10 ms460 KiB
#include <iostream> using namespace std; int t,n,f[210],b[210],a[210],q,ans[210]; bool ok[210]; int main() { cin>>t; while(t--) { ans[0]=0; cin>>n>>q; for(int i=1;i<=q;++i) cin>>f[i]; int j=1; for(int i=1;i<=n;++i) { if(f[j]==i) { ++j; ok[i]=true; } else ok[i]=false; b[i]=i-1; a[i]=i+1; } a[0]=1; f[q+1]=n+1; ++q; for(int i=2;i<=q;++i) { if(f[i]-f[i-1]>3) { int z=(f[i]+f[i-1])/2; while(ok[b[z]]==false&&ok[a[z]]==false&&b[z]!=f[i-1]) { ans[++ans[0]]=z; a[b[b[z]]]=z; b[a[a[z]]]=z; int q=a[a[z]]; a[a[z]]=n+1; a[z]=q; q=b[b[z]]; b[b[z]]=0; b[z]=q; } } } --q; for(int i=1;i<=n;++i) { while(ok[b[i]]==false&&ok[a[i]]==false&&b[i]!=0&&a[i]!=n+1) { ans[++ans[0]]=i; a[b[b[i]]]=i; b[a[a[i]]]=i; int q=a[a[i]]; a[a[i]]=n+1; a[i]=q; q=b[b[i]]; b[b[i]]=0; b[i]=q; } } for(int i=a[0];i<=n;i=a[i]) { if(ok[i]==false) { ans[0]=-1; break; } } cout<<ans[0]<<'\n'; for(int i=1;i<=ans[0];++i) cout<<ans[i]<<' '; if(ans[0]>0) cout<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...