Submission #1055914

#TimeUsernameProblemLanguageResultExecution timeMemory
1055914tamir1Xylophone (JOI18_xylophone)C++17
0 / 100
1 ms344 KiB
#include<bits/stdc++.h> #include "xylophone.h" using namespace std; static int A[5000]; int x[5001],y[5001]; void solve(int N) { int l=1,r=N,mid,i,mx=1,idx=0; while(r>l){ mid=(r+l+1)/2; if(query(mid,N)==N-1) l=mid; else r=mid-1; } A[l]=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); if(l<N) A[l+1]=x[l+1]+1; for(i=l+2;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]; } } } if(l>1) A[l-1]=x[l]+1; for(i=l-2;i>=1;i--){ if(x[i+2]==y[i+2]){ if(A[i+1]>A[i+2]) A[i]=A[i+1]-x[i+1]; else A[i]=A[i+1]-x[i+1]; } else{ if(y[i+2]!=x[i+1]){ if(A[i+1]>A[i+2]) A[i]=A[i+1]+x[i+1]; else A[i]=A[i+1]-x[i+1]; } else{ if(A[i+2]>A[i+1]) A[i]=A[i+1]+x[i+1]; else A[i]=A[i+1]-x[i+1]; } } } for(i=1;i<=N;i++) answer(i,A[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:7:20: warning: unused variable 'mx' [-Wunused-variable]
    7 |  int l=1,r=N,mid,i,mx=1,idx=0;
      |                    ^~
xylophone.cpp:7:25: warning: unused variable 'idx' [-Wunused-variable]
    7 |  int l=1,r=N,mid,i,mx=1,idx=0;
      |                         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...