제출 #1162627

#제출 시각아이디문제언어결과실행 시간메모리
1162627gelastropodXylophone (JOI18_xylophone)C++20
100 / 100
26 ms472 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; static int A[5000]; void solve(int N) { vector<int> ans; ans.push_back(0); int val = query(1, 2); ans.push_back(val); for (int i = 2; i < N; i++) { int val1 = query(i - 1, i + 1); int val2 = query(i, i + 1); int prev1 = ans[i - 2]; int prev2 = ans[i - 1]; int crnt = prev2 - val2; int minv = min(min(prev1, prev2), crnt); int maxv = max(max(prev1, prev2), crnt); if (maxv - minv == val1) { ans.push_back(crnt); } else { ans.push_back(prev2 + val2); } } int minelem = INT_MAX; for (int i = 0; i < N; i++) { minelem = min(minelem, ans[i]); } int adding = 1 - minelem; for (int i = 0; i < N; i++) { ans[i] += adding; } bool found1 = false; bool reversed = false; for (int i = 0; i < N; i++) { if (ans[i] == 1) { found1 = true; } if (ans[i] == N && !found1) { reversed = true; } } for (int i = 0; i < N; i++) { if (reversed) { answer(i + 1, N + 1 - ans[i]); } else { answer(i + 1, ans[i]); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...