# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
255414 | ChrisT | Xylophone (JOI18_xylophone) | C++17 | 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;
bool same[MN]; int diff[MN];
void solve (int n) {
for (int i = 1; i < n; i++) diff[i] = query(i,i+1);
for (int i = 1; i + 1 < n; i++) same[i+1] = query(i,i+2) == diff[i] + diff[i+1];
for (int ree = 0; ree <= 1; ree++) {
int lt = ree; vector<int> perm(n+1);
for (int st = 1; st <= n; st++) {
lt = ree; perm[1] = st;
for (int j = 2; j <= n; j++) {
if (lt) perm[j] = perm[j-1] - diff[j-1];
else perm[j] = perm[j-1] + diff[j-1];
if (perm[j] < 1 || perm[j] > n) goto fail;
lt ^= same[j] ^ 1;
}
for (int i = 1; i <= n; i++) {
if (perm[i] == 1) break;
if (perm[i] == n) goto fail;
}
for (int i = 1; i <= n; i++) answer(i,perm[i]);
return;
fail:;
}
}
assert(0);
}