제출 #711620

#제출 시각아이디문제언어결과실행 시간메모리
711620CyanmondXylophone (JOI18_xylophone)C++17
100 / 100
111 ms408 KiB
#include "xylophone.h" #include <bits/stdc++.h> int ask(int l, int r) { return query(l + 1, r + 1); } void solve(int N) { std::vector<int> ans(N); ans[0] = 0; ans[1] = ask(0, 1); for (int i = 2; i < N; ++i) { int v1 = ask(i - 2, i), v2 = ask(i - 1, i); if (ans[i - 2] < ans[i - 1]) { if (v1 == ans[i - 1] - ans[i - 2]) { ans[i] = ans[i - 1] - v2; } else if (v1 == v2) { ans[i] = ans[i - 1] - v2; } else { ans[i] = ans[i - 1] + v2; } } else { if (v1 == ans[i - 2] - ans[i - 1]) { ans[i] = ans[i - 1] + v2; } else if (v1 == v2) { ans[i] = ans[i - 1] + v2; } else { ans[i] = ans[i - 1] - v2; } } } int minId = (int)(std::min_element(ans.begin(), ans.end()) - ans.begin()); int maxId = (int)(std::max_element(ans.begin(), ans.end()) - ans.begin()); if (minId > maxId) { for (auto &e : ans) e = -e; std::swap(minId, maxId); } const int v = ans[minId]; for (auto &e : ans) e -= v; for (int i = 0; i < N; ++i) { answer(i + 1, ans[i] + 1); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...