# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502264 | vrohak | 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 <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
void solve(int N) {
int A[N];
A[0] = 0;
int D[N - 1];
int T[N - 2];
for(int i = 1; i < N; i++) {
D[i - 1] = query(i, i + 1);
}
for(int i = 2; i < N; i++) {
T[i - 2] = query(i - 1, i + 1);
}
A[1] = D[0];
bool up = true;
for(int i = 2; i < N; i++) {
if(D[i - 2] + D[i - 1] != T[i - 2]) {
up = !up;
}
A[i] = A[i - 1] + D[i - 1] * ((int)up * 2 - 1);
}
int rj1[N+1], rj2[N+1];
int mx = 0, mn = 0;
int idx1 = 0, idx2 = 0;
for(int i = 1; i < N; i++) {
mn = min(mn, A[i]);
}
mn = (-1)*mn+1;
for(int i=0;i<N;i++){
rj1[i] = A[i]+mn;
rj2[i] = -A[i];
}
mn=0;
for(int i = 1; i < N; i++) {
mn = min(mn, rj2[i]);
}
mn = (-1)*mn+1;
for(int i=0;i<N;i++) rj2[i]+=mn;
for(int i=0;i<N;i++){
if(rj1[i] == 1) idx1 = i;
if(rj1[i] == n) idx2 = i;
}
if(idx1 < idx2) {
for(int i = 0; i < N; i++) {
answer(i + 1, rj1[i]);
}
} else {
for(int i = 0; i < N; i++) {
answer(i + 1, rj2[i]);
}
}
return;
}