Submission #896131

#TimeUsernameProblemLanguageResultExecution timeMemory
896131AndreyXylophone (JOI18_xylophone)C++14
100 / 100
58 ms600 KiB
#include "xylophone.h" #include<bits/stdc++.h> using namespace std; void solve(int N) { int n = N; vector<int> dif(n-1); dif[0] = query(1,2); for(int i = 1; i < n-1; i++) { dif[i] = query(i+1,i+2); if((abs(dif[i-1])+dif[i] == query(i,i+2)) == (dif[i-1] < 0)) { dif[i]*=-1; } } vector<int> ans(n); ans[0] = 0; int sm = 0,p1,p2; for(int i = 1; i < n; i++) { ans[i] = ans[i-1]+dif[i-1]; sm = min(sm,ans[i]); } for(int i = 0; i < n; i++) { ans[i] = ans[i]-sm+1; if(ans[i] == 1) { p1 = i; } else if(ans[i] == n) { p2 = i; } } if(p1 > p2) { for(int i = 0; i < n; i++) { ans[i] = n-ans[i]+1; } } for(int i = 0; i < n; i++) { answer(i+1,ans[i]); } }

Compilation message (stderr)

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