Submission #102444

#TimeUsernameProblemLanguageResultExecution timeMemory
102444Dat160601Xylophone (JOI18_xylophone)C++17
100 / 100
87 ms512 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second const int N = 5007; int p[N]; void solve(int n){ if(n == 1){ answer(1, 1); return; } p[1] = 0; p[2] = query(1, 2); for(int i = 3; i <= n; i++){ int ret1 = query(i - 1, i), ret2 = query(i - 2, i); if(p[i - 1] > p[i - 2]){ if(ret2 == ret1 + abs(p[i - 1] - p[i - 2])) p[i] = p[i - 1] + ret1; else p[i] = p[i - 1] - ret1; } else{ if(ret2 == ret1 + abs(p[i - 1] - p[i - 2])) p[i] = p[i - 1] - ret1; else p[i] = p[i - 1] + ret1; } } int val = 1e9; for(int i = 1; i <= n; i++){ if(p[i] < val) val = p[i]; } int pos1, posn; for(int i = 1; i <= n; i++){ p[i] += (1 - val); if(p[i] == 1) pos1 = i; if(p[i] == n) posn = i; } if(pos1 > posn){ for(int i = 1; i <= n; i++){ p[i] = n - p[i] + 1; } } for(int i = 1; i <= n; i++) answer(i, p[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:42:2: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if(pos1 > posn){
  ^~
xylophone.cpp:42:2: 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...