Submission #146231

#TimeUsernameProblemLanguageResultExecution timeMemory
146231DiuvenXylophone (JOI18_xylophone)C++14
0 / 100
2 ms376 KiB
#include "xylophone.h" #include <algorithm> using namespace std; static int P[5001], A[5001]; void solve(int n){ for(int i=2; i<=n; i++) P[i] = query(i-1, i); A[1] = 0; A[2] = P[2]; for(int i=3; i<=n; i++){ int sg = A[i-1]>A[i-2] ? 1 : -1; if(query(i-2, i)!=P[i-1]+P[i]) sg *= -1; A[i] = A[i-1] + sg*P[i]; } int x = min_element(A+1, A+n+1)-A; int y = max_element(A+1, A+n+1)-A; for(int i=1; i<=n; i++) A[i] -= A[x]-1; if(x>y) for(int i=1; i<=n; i++) A[i] = n-A[i]+1; for(int i=1; i<=n; i++) answer(i, A[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...