# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784262 | tvladm2009 | 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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
/// i almost made my last submission to pass
const int N = 5000 + 7;
int n;
int d2[N];
int d3[N];
int dir[N];
bool same[N];
int a[N];
int b[N];
int where[N];
bool isok() {
int mn = a[1];
for (int i = 1; i < n; i++) {
a[i + 1] = a[i] + dir[i] * d2[i];
mn = min(mn, a[i + 1]);
}
for (int i = 1; i <= n; i++) {
a[i] -= (mn - 1);
}
for (int i = 1; i <= n; i++) {
where[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] < 1 || a[i] > n) {
return false;
}
if (where[a[i]]) {
return false;
}
where[a[i]] = i;
}
return where[1] <= where[n];
}
void solve(int nn) {
n = nn;
for (int i = 1; i + 1 <= n; i++) {
d2[i] = query(i, i + 1);
}
for (int i = 1; i + 2 <= n; i++) {
d3[i] = query(i, i + 2);
}
/**
a[i] - a[i + 1] = +- d2[i]
**/
dir[1] = +1;
for (int i = 1; i + 2 <= n; i++) {
if (d2[i] + d2[i + 1] == d3[i]) {
/// direction[i] = direction[i + 1]
dir[i + 1] = dir[i];
} else {
/// direction[i] != direction[i + 1]
dir[i + 1] = -dir[i];
}
}
if (!isok()) {
for (int i = 1; i < n; i++) {
dir[i] *= -1;
}
assert(isok());
}
for (int i = 1; i <= n; i++) {
answer(i, a[i]);
}
return 0;
}