Submission #389561

#TimeUsernameProblemLanguageResultExecution timeMemory
389561maximath_1Xylophone (JOI18_xylophone)C++11
100 / 100
161 ms456 KiB
#include "xylophone.h" #include <vector> #include <math.h> #include <iostream> #include <assert.h> using namespace std; int diff[5005]; int ans[5005]; void solve(int N){ for(int i = 2; i <= N; i ++){ if(i == 2) diff[i] = query(i - 1, i); else{ int nw = query(i - 1, i), bf = query(i - 2, i); if(abs(nw) + abs(diff[i - 1]) == bf){ diff[i] = nw; if(diff[i - 1] < 0) diff[i] *= -1; assert(abs(abs(diff[i - 1]) + abs(diff[i])) == bf); }else{ diff[i] = nw; if(diff[i - 1] > 0) diff[i] *= -1; assert(max(abs(diff[i - 1]), abs(diff[i])) == bf); } } } ans[1] = 1; for(int i = 2; i <= N; i ++) ans[i] = diff[i] + ans[i - 1]; int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0; for(int i = 1; i <= N; i ++){ if(mn > ans[i]){ mn = ans[i]; mnid = i; } if(mx < ans[i]){ mx = ans[i]; mxid = i; } } for(int i = 1; i <= N; i ++) ans[i] += -mn + 1; if(mnid > mxid){ ans[1] = 1; for(int i = 2; i <= N; i ++) ans[i] = -diff[i] + ans[i - 1]; int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0; for(int i = 1; i <= N; i ++){ if(mn > ans[i]){ mn = ans[i]; mnid = i; } if(mx < ans[i]){ mx = ans[i]; mxid = i; } } for(int i = 1; i <= N; i ++) ans[i] += -mn + 1; } for(int i = 1; i <= N; i ++) answer(i, ans[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:50:38: warning: variable 'mnid' set but not used [-Wunused-but-set-variable]
   50 |   int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
      |                                      ^~~~
xylophone.cpp:50:48: warning: variable 'mxid' set but not used [-Wunused-but-set-variable]
   50 |   int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
      |                                                ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...