Submission #302970

#TimeUsernameProblemLanguageResultExecution timeMemory
302970iliccmarkoXylophone (JOI18_xylophone)C++14
100 / 100
68 ms680 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" using namespace std; int used[5005]; int a[5005]; void solve(int n) { int l = 1; int r = n - 1; int start; while(l<=r) { int mid = (l+r)/2; if(query(mid, n)==n-1) { start = mid; l = mid + 1; } else { r = mid - 1; } } if(start-1>0) { a[start-1] = 1 + query(start-1, start); used[a[start-1]] = 1; } a[start+1] = 1 + query(start, start+1); used[a[start+1]] = 1; a[start] = 1; used[1] = 1; for(int i = start-2;i>0;i--) { int s = query(i, i+1); int m1 = a[i+1] + s; int m2 = a[i+1] - s; if(m1>=n||used[m1]) { a[i] = m2; used[m2] = 1; } else if(m2<=0||used[m2]) { a[i] = m1; used[m1] = 1; } else { int ss = query(i, i+2); if(max({m1, a[i+1], a[i+2]}) - min({m1, a[i+1], a[i+2]}) == ss) { a[i] = m1; used[m1] = 1; } else { a[i] = m2; used[m2] = 1; } } } for(int i = start+2;i<=n;i++) { int s = query(i-1, i); int m1 = a[i-1] + s; int m2 = a[i-1] - s; if(m1>n||used[m1]) { a[i] = m2; used[m2] = 1; } else if(m2<=1||used[m2]) { a[i] = m1; used[m1] = 1; } else { int ss = query(i-2, i); if(max({m1, a[i-1], a[i-2]}) - min({m1, a[i-1], a[i-2]}) == ss) { a[i] = m1; used[m1] = 1; } else { a[i] = m2; used[m2] = 1; } } } for(int i = 1;i<=n;i++) { answer(i, a[i]); } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:37:14: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     a[start] = 1;
      |     ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...