Submission #702858

#TimeUsernameProblemLanguageResultExecution timeMemory
702858hmm789Xylophone (JOI18_xylophone)C++14
0 / 100
0 ms208 KiB
#include "xylophone.h" static int A[5000]; void solve(int n) { int a[n], ans[n+1]; for(int i = 1; i < n; i++) a[i] = query(i, i+1); int l = 1, r = n; while(l < r) { int m = (l+r)/2; if(query(m, n) == n-1) l = m+1; else r = m; } ans[l-1] = 1; ans[l] = a[l-1]+1; for(int i = l+1; i <= n; i++) { int tmp = query(i-2, i); if(tmp < ans[i-1] && ans[i-2] > ans[i-1] || tmp > ans[i-1] && ans[i-2] < ans[i-1]) ans[i] = ans[i-1]+a[i-1]; else ans[i] = ans[i-1]-a[i-1]; } for(int i = l-2; i >= 0; i--) { int tmp = query(i, i+2); if(tmp < ans[i+1] && ans[i+2] > ans[i+1] || tmp > ans[i+1] && ans[i+2] < ans[i+1]) ans[i] = ans[i+1]+a[i+1]; else ans[i] = ans[i+1]-a[i+1]; } for(int i = 1; i <= n; i++) answer(i, ans[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   18 |   if(tmp < ans[i-1] && ans[i-2] > ans[i-1] || tmp > ans[i-1] && ans[i-2] < ans[i-1]) ans[i] = ans[i-1]+a[i-1];
      |      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:23:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   23 |   if(tmp < ans[i+1] && ans[i+2] > ans[i+1] || tmp > ans[i+1] && ans[i+2] < ans[i+1]) ans[i] = ans[i+1]+a[i+1];
      |      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp: At global scope:
xylophone.cpp:3:12: warning: 'A' defined but not used [-Wunused-variable]
    3 | static int A[5000];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...