제출 #278090

#제출 시각아이디문제언어결과실행 시간메모리
278090errayXylophone (JOI18_xylophone)C++17
0 / 100
1 ms256 KiB
// author: erray #include<bits/stdc++.h> #include "xylophone.h" using namespace std; //int query(int s, int e); //int answer(int ind, int v); void solve(int n) { vector<int> f(n); f[1] = query(1, 2); for (int i = 2; i < n; ++i) { int th = query(i - 1, i + 1), tw = query(i, i + 1); if (th == abs(f[i - 1])) { f[i] = f[i - 1] + (f[i - 1] > 0 ? -1 : 1) * tw; } else if (th > abs(f[i - 1])) { if (tw > th) { f[i] = f[i - 1] + (f[i - 1] > 0 ? -1 : 1) * tw; } else { f[i] = f[i - 1] + (f[i - 1] > 0 ? 1 : -1) * tw; } } } vector<int> pref(n); for (int i = 0; i < n; ++i) { pref[i] = pref[i - (i > 0)] + f[i]; } int ind1 = (int) (max_element(pref.begin(), pref.end()) - pref.begin()), ind2 = (int) (min_element(pref.begin(), pref.end()) - pref.begin()); if (ind2 > ind1) { swap(ind2, ind1); for (auto& el : f) el = -el; } swap(ind1, ind2); vector<int> ans(n); ans[ind1] = 1; for (int i = ind1 + 1; i < n; ++i) { ans[i] = ans[i - 1] + f[i]; } for (int i = ind1 - 1; i >= 0; --i) { ans[i] = ans[i + 1] + -f[i + 1]; } for (int i = 0; i < n; ++i) { answer(i + 1, ans[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...