# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502539 | fabijan_cikac | 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"
void solve(int N){
map<int, map<int, int> > m; vector<pair<int, int> > v;
int a[2 * 1e4]; bool b = true;
int sol[2 * 1e4]; m[0][1] = query(0, 1);
for (int i = 2; i < N; ++i){
m[i - 2][i] = query(i - 2, i);
m[i - 1][i] = query(i - 1, i);
}
//a[0] < a[1]
a[0] = 0; a[1] = m[0][1];
for (int i = 2; i < N; ++i){
bool c = false;
for (int j = -1; j <= 1; ++j){
if (j == 0) continue;
a[i] = a[i - 1] + j * m[i - 1][i];
if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i]){
c = true; break;
}
}
if (!c) b = false;
}
for (int i = 0; i < N; ++i)
v.push_back({a[i], i});
sort(v.begin(), v.end()); int x, y;
for (int i = 0; i < n; ++i){
sol[v[i].second] = i + 1;
if (i + 1 == 1) x = v[i].second;
if (i + 1 == N) y = v[i].second;
}
if (!b || x > y){
a[0] = 0; a[1] = -m[0][1]; b = true;
for (int i = 2; i < N; ++i){
bool c = false;
for (int j = -1; j <= 1; ++j){
if (j == 0) continue;
a[i] = a[i - 1] + j * m[i - 1][i];
if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i]){
c = true; break;
}
}
if (!c) b = false;
}
v.clear();
for (int i = 0; i < N; ++i)
v.push_back({a[i], i});
sort(v.begin(), v.end()); int x, y;
for (int i = 0; i < n; ++i){
sol[v[i].second] = i + 1;
if (i + 1 == 1) x = v[i].second;
if (i + 1 == N) y = v[i].second;
}
}
for (int i = 0; i < n; ++i)
answer(i + 1, sol[i]);
return;
}