# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102467 | 2019-03-25T07:17:08 Z | IOrtroiii | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; const int N = 5050; int a[N]; int p[N]; void solve(int n) { if (n == 1) { solve(1, 1); } a[1] = 0; a[2] = query(1, 2); for (int i = 3; i <= n; ++i) { int u = query(i - 1, i), v = query(i - 2, i); if (a[i - 1] < a[i - 2]) { if (v == u + a[i - 2] - a[i - 1]) { a[i] = a[i - 1] - u; } else { a[i] = a[i - 1] + u; } } else { if (v == u + a[i - 1] - a[i - 2]) { a[i] = a[i - 1] + u; } else { a[i] = a[i - 1] - u; } } } int val = *min_element(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) { a[i] += (1 - val); p[a[i]] = i; } if (p[1] > p[n]) { for (int i = 1; i <= n; ++i) { a[i] = n + 1 - a[i]; } } for (int i = 1; i <= n; ++i) { answer(i, a[i]); } }