Submission #114841

#TimeUsernameProblemLanguageResultExecution timeMemory
114841maruiiXylophone (JOI18_xylophone)C++14
0 / 100
2 ms384 KiB
#include "xylophone.h" #include <algorithm> #include <cstdio> static int A[5000]; int X[5000], ans[5000]; void solve(int N) { for (int i = 0; i < N - 1; ++i) X[i] = query(i + 1, i + 2); ans[1] = X[0]; for (int i = 0; i < N - 2; ++i) { int t = query(i + 1, i + 3); if (X[i] + X[i+1] == t) { if(i == 0 || ans[i+1] > ans[i]) ans[i+2] = ans[i] + t; else ans[i] = ans[i] - t; } else { if (i == 0 || ans[i+1] > ans[i]) ans[i+2] = ans[i+1] - X[i+1]; else ans[i+2] = ans[i+1] + X[i+1]; } } int m = *std::min_element(ans, ans + N) - 1; int a, b; for (int i = 0; i < N; ++i) { ans[i] -= m; if (ans[i] == 1) a = i; if (ans[i] == N) b = i; } for(int i = 1; i <= N; i++) { if (a > b) ans[i-1] = N + 1 - ans[i-1]; answer(i, ans[i-1]); } }

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:30:3: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (a > b) ans[i-1] = N + 1 - ans[i-1];
   ^~
xylophone.cpp:30:3: warning: 'a' 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...