제출 #654363

#제출 시각아이디문제언어결과실행 시간메모리
654363uyluluXylophone (JOI18_xylophone)C++14
0 / 100
1 ms208 KiB
#include "xylophone.h" #include<bits/stdc++.h> using namespace std; const int N = 5e3; int res[N + 1]; void solve(int n) { int l = 1,r = n; int pos; while(l < r) { int mid = (l + r)/2; if(query(mid,n) == n - 1) { l = mid + 1; pos = mid; } else { r = mid; } } res[pos] = 1; for(int i = pos - 1;i >= 1;i--) { int w = query(i,i + 1); if(res[i + 1] + w > n) { res[i] = res[i + 1] - w; continue; } if(res[i + 1] <= w) { res[i] = res[i + 1] + w; continue; } vector<int> st = {res[i + 1],res[i + 2]}; sort(st.begin(),st.end()); int asd = query(i,i + 2); if(asd == st[1] - st[0]) { res[i] = st[1] - w; } else { if(asd == w) { res[i] = st[1] - w; } else { res[i] = st[1] + w; } } } for(int i = pos + 1;i <= n;i++) { int w = query(i - 1,i); if(res[i - 1] <= w) { res[i] = res[i - 1] + w; continue; } if(res[i - 1] + w > n) { res[i] = res[i - 1] - w; continue; } vector<int> st = {res[i - 1],res[i - 2]}; sort(st.begin(),st.end()); int asd = query(i - 2,i); if(asd == st[1] - st[0]) { res[i] = st[1] - w; } else { if(asd == w) { res[i] = st[1] - w; } else { res[i] = st[1] + w; } } } for(int i = 1;i <= n;i++) { answer(i,res[i]); } return; }

컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:11:6: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |  int pos;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...