제출 #882086

#제출 시각아이디문제언어결과실행 시간메모리
882086SharkyXylophone (JOI18_xylophone)C++17
100 / 100
69 ms740 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int N) { vector<int> di(N + 1); for (int i = 1; i <= N - 1; i++) di[i] = query(i, i + 1); vector<int> s(N + 1, -1); for (int i = 1; i <= N - 2; i++) { int q = query(i, i + 2); if (di[i] + di[i + 1] == q) s[i + 1] = s[i]; else s[i + 1] = (s[i] == -1 ? 1 : -1); } vector<int> a(N + 1, 0); a[1] = 0; for (int i = 2; i <= N; i++) { a[i] = a[i - 1] + di[i - 1] * s[i - 1]; } int mn = 0; for (int i = 1; i <= N; i++) mn = min(mn, a[i]); mn = -mn + 1; int op = mn; int mn_idx = 0, mx_idx = 0; mn = N + 1; int mx = 0; for (int i = 1; i <= N; i++) { a[i] += op; if (a[i] < mn) mn = a[i], mn_idx = i; if (a[i] > mx) mx = a[i], mx_idx = i; } if (mx_idx < mn_idx) { for (int i = 1; i <= N; i++) a[i] = N + 1 - a[i]; } for (int i = 1; i <= N; i++) answer(i, a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...