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) {
int A[N+1], B[N+1];
A[1] = B[1] = 500069;
int ma = 1, mb = 1;
for (int i = 2; i <= N; i++) {
int q1 = query(i-1, i);
if (i == 2) {
A[2] = A[1] + q1;
B[2] = B[1] - q1;
} else {
int q2 = query(i-2, i);
if (A[i-2] < A[i-1]) {
if (q2 == q1 + A[i-1] - A[i-2]) {
A[i] = A[i-1] + q1;
B[i] = B[i-1] - q1;
} else {
A[i] = A[i-1] - q1;
B[i] = B[i-1] + q1;
}
} else {
if (q2 == q1 + A[i-2] - A[i-1]) {
A[i] = A[i-1] - q1;
B[i] = B[i-1] + q1;
} else {
A[i] = A[i-1] + q1;
B[i] = B[i-1] - q1;
}
}
}
ma = A[ma] > A[i] ? i : ma;
mb = B[mb] > B[i] ? i : mb;
}
if (ma < mb) {
int sub = A[ma] - 1;
for (int i = 1; i <= N; i++) {
answer(i, A[i] - sub);
}
} else {
int sub = B[ma] - 1;
for (int i = 1; i <= N; i++) {
answer(i, B[i] - sub);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |