Submission #230945

#TimeUsernameProblemLanguageResultExecution timeMemory
230945AlexLuchianovXylophone (JOI18_xylophone)C++14
100 / 100
115 ms632 KiB
#include "xylophone.h" #include <iostream> int const nmax = 5000; static int A[5000]; int diff[1 + nmax]; int change[1 + nmax]; int v[1 + nmax]; void solve(int n) { for(int i = 1;i < n; i++) diff[i] = query(i, i + 1); change[1] = 1; for(int i = 2; i < n; i++){ if(diff[i - 1] + diff[i] == query(i - 1, i + 1)) change[i] = change[i - 1]; else change[i] = !change[i - 1]; } v[1] = 0; for(int i = 2;i <= n; i++) if(change[i - 1] == 1) v[i] = v[i - 1] + diff[i - 1]; else v[i] = v[i - 1] - diff[i - 1]; int smin = 0; for(int i = 1; i <= n; i++) smin = std::min(smin, v[i]); for(int i = 1;i <= n; i++) v[i] = v[i] - smin + 1; int pos1, posn; for(int i = 1;i <= n; i++) if(v[i] == 1) pos1 = i; else if(v[i] == n) posn = i; if(posn < pos1) for(int i = 1; i <= n; i++) v[i] = n - v[i] + 1; for(int i = 1;i <= n; i++) answer(i, v[i]); } /* 5 2 1 5 3 4 */

Compilation message (stderr)

xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
 static int A[5000];
            ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:38:3: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(posn < pos1)
   ^~
xylophone.cpp:38:3: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...