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;
int arr[5001];
void solve(int n) {
map<int,int> pos;
for (int i = 2; i <= n; ++i) {
int dif = query(i, n);
if (dif < n - 1) {
arr[i - 1] = 1;
pos[1] = i - 1;
break;
}
}
for (int i = pos[1]; i < n; ++i) {
int dif = query(i, i + 1);
int big = arr[i] + dif;
int small = arr[i] - dif;
if (pos.count(small) || small < 1) {
arr[i + 1] = big;
pos[big] = i + 1;
}
else if (pos.count(big) || big > n) {
arr[i + 1] = small;
pos[small] = i + 1;
}
else {
int new_dif = query(i - 1, i + 1);
if (arr[i - 1] > arr[i]) {
if (dif < new_dif) {
arr[i + 1] = big;
pos[big] = i + 1;
}
else {
arr[i + 1] = small;
pos[small] = i + 1;
}
}
else {
if (dif < new_dif) {
arr[i + 1] = small;
pos[small] = i + 1;
}
else {
arr[i + 1] = big;
pos[big] = i + 1;
}
}
}
}
for (int i = pos[1]; i > 1; --i) {
int dif = query(i - 1, i);
int big = arr[i] + dif;
int small = arr[i] - dif;
if (pos.count(small) || small < 1) {
arr[i - 1] = big;
pos[big] = i + 1;
}
else if (pos.count(big) || big > n) {
arr[i - 1] = small;
pos[small] = i + 1;
}
else {
int new_dif = query(i - 1, i + 1);
if (arr[i + 1] > arr[i]) {
if (dif < new_dif) {
arr[i - 1] = big;
pos[big] = i + 1;
}
else {
arr[i - 1] = small;
pos[small] = i + 1;
}
}
else {
if (dif > new_dif) {
arr[i - 1] = small;
pos[small] = i + 1;
}
else {
arr[i - 1] = big;
pos[big] = i + 1;
}
}
}
}
for (int i = 1; i <= n; ++i) {
//cout << arr[i] << ' ';
answer(i, arr[i]);
}
//cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |