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 <algorithm>
using namespace std;
static int P[5001], A[5001];
void solve(int n){
for(int i=2; i<=n; i++) P[i] = query(i-1, i);
A[1] = 0; A[2] = P[2];
for(int i=3; i<=n; i++){
int sg = A[i-1]>A[i-2] ? 1 : -1;
if(query(i-2, i)!=P[i-1]+P[i]) sg *= -1;
A[i] = A[i-1] + sg*P[i];
}
int x = min_element(A+1, A+n+1)-A, z=A[x];
int y = max_element(A+1, A+n+1)-A;
for(int i=1; i<=n; i++) A[i] -= z-1;
if(x>y) for(int i=1; i<=n; i++) A[i] = n-A[i]+1;
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... |