# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58556 | gusfring | Xylophone (JOI18_xylophone) | C++14 | 0 ms | 0 KiB |
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;
const int MAXN = 5e3 + 5;
int A[MAXN], dif[MAXN];
void solve(int N){
for(int i=1; i<N; ++i) dif[i - 1] = query(i, i + 1);
int sign = 1;
A[0] = 0, A[1] = dif[0];
for(int i=1; i<N-1; ++i){
if(query(i, i + 2) != (dif[i - 1] + dif[i])) sign = -sign;
A[i + 1] = A[i] + sign * dif[i];
}
int mn = 0, mx = 0;
for(int i=1; i<N; ++i){
if(A[i] < A[mn]) mn = i;
if(A[i] > A[mx]) mx = i;
}
if(mn > mx){
for(int i=1; i<N; ++i) A[i] = -A[i];
swap(mn, mx);
}
for(int i=0; i<N; ++i) answer(i + 1, A[i] - A[mn] + 1);
}