# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102467 | IOrtroiii | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]);
}
}