Submission #314985

#TimeUsernameProblemLanguageResultExecution timeMemory
314985amunduzbaevJousting tournament (IOI12_tournament)C++14
0 / 100
18 ms2048 KiB
//#include "grader.cpp" #include <bits/stdc++.h> using namespace std; int n, c, last, k[505], s[505], e[505], tmp[505], used[505], tmp2[505]; int solve(int pos){ int j=0; for(int i=0;i<n;i++) tmp[i]=tmp2[i]; int done=0; for(int i=0;i<c;i++){ int l=s[i], r=e[i],m=0; for(;l<=r;l++) m=max(m,tmp[l]); l=s[i]; for(;l<=r;l++) tmp[l]=m; if(m==last){ pos=r, j++;} if(tmp[pos]!=last) return j; } return j; } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { n=N, c=C, last=R; for(int i=0;i<n-1;i++) k[i]=K[i]; for(int i=0;i<c;i++) s[i]=S[i],e[i]=E[i]; tmp2[0]=last; for(int i=1;i<n;i++){ tmp2[i]=k[i-1]; } for(int i=0;i<c;i++){ int l=s[i],r=e[i]; if(s[i+1]>=l){ s[i+1]+=(r-l); } if(e[i+1]>=l){ e[i+1]+=(r-l); } } int ans,mx=0; for(int pos=0;pos<n;pos++){ int sl=solve(pos); if(sl>mx){ mx=sl; ans=pos; } swap(tmp2[pos],tmp2[pos+1]); } return ans; } /* 5 3 3 1 0 2 4 1 3 0 1 0 1 */

Compilation message (stderr)

tournament.cpp: In function 'int solve(int)':
tournament.cpp:8:9: warning: unused variable 'done' [-Wunused-variable]
    8 |     int done=0;
      |         ^~~~
tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:49:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |     return ans;
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...