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> di(N + 1);
for (int i = 1; i <= N - 1; i++) di[i] = query(i, i + 1);
vector<int> s(N + 1, -1);
for (int i = 1; i <= N - 2; i++) {
int q = query(i, i + 2);
if (di[i] + di[i + 1] == q) s[i + 1] = s[i];
else s[i + 1] = (s[i] == -1 ? 1 : -1);
}
vector<int> a(N + 1, 0);
a[1] = 0;
for (int i = 2; i <= N; i++) {
a[i] = a[i - 1] + di[i - 1] * s[i - 1];
}
int mn = 0;
for (int i = 1; i <= N; i++) mn = min(mn, a[i]);
mn = -mn + 1;
int op = mn;
int mn_idx = 0, mx_idx = 0;
mn = N + 1;
int mx = 0;
for (int i = 1; i <= N; i++) {
a[i] += op;
if (a[i] < mn) mn = a[i], mn_idx = i;
if (a[i] > mx) mx = a[i], mx_idx = i;
}
if (mx_idx < mn_idx) {
for (int i = 1; i <= N; i++) a[i] = N + 1 - a[i];
}
for (int i = 1; i <= N; i++) answer(i, a[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |