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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
vector<int> a(n + 1);
vector<int> b(n + 1);
for (int i = 1; i <= n - 1; i++) {
a[i] = query(i, i + 1);
}
for (int i = 1; i <= n - 2; i++) {
b[i] = query(i, i + 2);
}
vector<bool> f(n + 1);
vector<int> res(n + 1);
for (int i = 1; i <= n; i++) {
res[1] = i;
for (int j = -1; j <= 1; j += 2) {
fill(f.begin(), f.end(), false);
f[res[1]] = true;
res[2] = res[1] + a[1] * j;
if (res[2] < 1 || res[2] > n || f[res[2]]) {
continue;
}
f[res[2]] = true;
bool ok = true;
for (int k = 3; k <= n; k++) {
bool g = false;
for (int l = -1; l <= 1; l += 2) {
res[k] = res[k - 1] + a[k - 1] * l;
if (res[k] < 1 || res[k] > n || f[res[k]]) {
continue;
}
if (max({res[k - 2], res[k - 1], res[k]}) - min({res[k - 2], res[k - 1], res[k]}) != b[k - 2]) {
continue;
}
f[res[k]] = true;
g = true;
break;
}
if (!g) {
ok = false;
break;
}
}
if (ok) {
for (int i = 1; i <= n; i++) {
answer(i, res[i]);
}
return;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |