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;
void solve(int N){
map<int, map<int, int> > m; vector<pair<int, int> > v;
int a[6000]; bool b = true;
int sol[6000]; 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; break;
}
}
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 = 2; i < N; ++i){
for (int j = 1; j <= 2; ++j){
int mini = 1e9; int maks = -1;
for (int k = i - j; k <= i; ++k){
mini = min(mini, sol[k]); maks = max(maks, sol[k]);
}
if (maks - mini != m[i - j][i])
b = false;
}
}
if (!b || x > y){
a[0] = 0; a[1] = -m[0][1];
for (int i = 2; i < N; ++i){
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])
break;
}
}
v.clear();
for (int i = 0; i < N; ++i)
v.push_back({a[i], i});
sort(v.begin(), v.end());
for (int i = 0; i < N; ++i)
sol[v[i].second] = i + 1;
bool b = true;
for (int i = 2; i < N; ++i){
for (int j = 1; j <= 2; ++j){
int mini = 1e9; int maks = -1;
for (int k = i - j; k <= i; ++k){
mini = min(mini, sol[k]); maks = max(maks, sol[k]);
}
if (maks - mini != m[i - j][i])
b = false;
}
}
for (int i = 0; i < N; ++i){
if (sol[i] == 1) x = i;
else if (sol[i] == N)
y = i;
}
if (x > y)
b = false;
if (!b){
int cnt = 0;
while (cnt < 1e11)
++cnt;
}
}
for (int i = 0; i < N; ++i)
answer(i + 1, sol[i]);
return;
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:47:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | if (!b || x > y){
| ~~^~~
xylophone.cpp:47:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |