Submission #1056058

#TimeUsernameProblemLanguageResultExecution timeMemory
1056058tamir1Xylophone (JOI18_xylophone)C++17
0 / 100
1 ms344 KiB
#include<bits/stdc++.h> #include "xylophone.h" using namespace std; static int A[5001]; int x[5001],y[5001],i,mn,ok[5001]; void solve(int N) { A[1]=1; for(i=2;i<=N;i++) x[i]=query(i-1,i); for(i=3;i<=N;i++) y[i]=query(i-2,i); A[2]=x[2]+1; for(i=3;i<=N;i++){ if(x[i-1]==y[i]){ if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i]; else A[i]=A[i-1]+x[i]; } else{ if(y[i]!=x[i]){ if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i]; else A[i]=A[i-1]-x[i]; } else{ if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i]; else A[i]=A[i-1]-x[i]; } } } mn=10000; for(i=1;i<=N;i++){ mn=min(A[i],mn); } mn=1-mn; for(i=1;i<=N;i++) A[i]+=mn; bool unen=1; for(i=1;i<=N;i++){ if(A[i]<1 || A[i]>N) unen=0; if(ok[A[i]]!=0) unen=0; ok[A[i]]=i; } if(ok[1]>ok[N]) unen=0; if(unen){ for(i=1;i<=N;i++) answer(i,A[i]); return; } A[1]=1; A[2]=x[2]-1; for(i=3;i<=N;i++){ if(x[i-1]==y[i]){ if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i]; else A[i]=A[i-1]+x[i]; } else{ if(y[i]!=x[i]){ if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i]; else A[i]=A[i-1]-x[i]; } else{ if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i]; else A[i]=A[i-1]-x[i]; } } } mn=10000; for(i=1;i<=N;i++){ mn=min(A[i],mn); } mn=1-mn; for(i=1;i<=N;i++) A[i]+=mn; for(i=1;i<=N;i++) answer(i,A[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...