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"
int arr[5005], adj[5005], three[5005];
void solve(int n)
{
for (int i = 1; i < n; i++)
adj[i] = query(i, i + 1);
for (int i = 2; i < n; i++)
three[i] = query(i - 1, i + 1);
arr[0] = 0;
arr[1] = adj[1];
for (int i = 2, dir = 1; i < n; i++)
{
if (three[i] != adj[i - 1] + adj[i])
dir ^= 1;
arr[i] = arr[i - 1] + adj[i] * (dir * 2 - 1);
}
int mnp = 0, mxp = 0;
for (int i = 0; i < n - 1; i++)
{
if (arr[i] < arr[mnp])
mnp = i;
if (arr[i] > arr[mxp])
mxp = i;
}
for (int i = 0; i < n; i++)
answer(i + 1, mnp < mxp ? arr[i] - arr[mnp] + 1 : arr[mxp] - arr[i] + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |