# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
516086 | lovrot | Xylophone (JOI18_xylophone) | C++11 | 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;
int rj[5000];
int ask(int s, int t){
return query(s + 1, t + 1);
}
void solve(int n){
rj[0] = 0;
rj[1] = rj[0] + ask(0, 1);
for(int i = 0; i + 2 < n; i++){
int cur = abs(rj[i] - rj[i + 1]);
int c = ask(i, i + 2);
if(c == cur){
int d = ask(i + 1, i + 2);
if(rj[i + 1] > rj[i]){
rj[i + 2] = rj[i + 1] - d;
}
else{
rj[i + 2] = rj[i + 1] + d;
}
}
else{
int d = ask(i + 1, i + 2);
if(c == d){
if(rj[i + 1] > rj[i]){
rj[i + 2] = rj[i + 1] - c;
}
else{
rj[i + 2] = rj[i + 1] + c;
}
}
else{
if(rj[i] > rj[i + 1]){
rj[i + 2] = rj[i] - c;
}
else{
rj[i + 2] = rj[i] + c;
}
}
}
}
int mn = 0, mx = 0;
for(int i = 0; i < n; i++){
if(rj[i] < rj[mn]) mn = i;
if(rj[i] > rj[mx]) mx = i;
}
if(mx < mn){
for(int i : a){
i *= -1;
}
}
mn = 1e9;
for(int i : a) mn = min(mn, i);
for(int i : a) i = i - mn + 1;
for(int i = 0 ; i < n ; i++){
answer(i + 1, rj[i]);
}
}