Submission #341444

#TimeUsernameProblemLanguageResultExecution timeMemory
341444KerimXylophone (JOI18_xylophone)C++17
100 / 100
145 ms20800 KiB
#include "xylophone.h" static int A[5000]; int dp[5005][5005],res[5005]; int ask(int x,int y){ if(dp[x][y])return dp[x][y]; return dp[x][y]=query(x,y); } int min(int a,int b){if(a>b)return b;return a;} void solve(int n) { res[0]=0;res[1]=ask(1,2); for(int j=0;j<2;j++){ int mn=min(res[1],0); for(int i=2;i<n;i++){ int a=ask(i-1,i); int b=ask(i,i+1); int c=ask(i-1,i+1); if(res[i-2]<res[i-1]){ if(a+b==c) res[i]=res[i-1]+b; else res[i]=res[i-1]-b; } else{ if(a+b==c) res[i]=res[i-1]-b; else res[i]=res[i-1]+b; } mn=min(mn,res[i]); }int ok=1,a=0,b=0; for(int i=0;i<n;i++){ if(res[i]>res[b])b=i;if(res[i]<res[a])a=i; ok&=(res[i]-mn>=0 and res[i]-mn<n); }ok&=(a<b); if(ok){ for(int i=0;i<n;i++) answer(i+1,res[i]-mn+1); return; }res[1]*=-1; } return; }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:32:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   32 |    if(res[i]>res[b])b=i;if(res[i]<res[a])a=i;
      |    ^~
xylophone.cpp:32:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   32 |    if(res[i]>res[b])b=i;if(res[i]<res[a])a=i;
      |                         ^~
xylophone.cpp: At global scope:
xylophone.cpp:2:12: warning: 'A' defined but not used [-Wunused-variable]
    2 | static int A[5000];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...