# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
763315 | vjudge1 | Xylophone (JOI18_xylophone) | C++17 | 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;
#define ll long long
void solve(int N){
cin>>N;
vector<int> duo(N+1,0);
vector<int> trio(N+1,0);
vector<int> arr(N+1,0);
for(int i=1;i<N;++i){
duo[i-1] = ask(i,i+1);
}
arr[1] = duo[0];
for(int i=2;i<N;++i){
trio[i-2] = ask(i-1,i+1);
}
bool greater = true;
for(int i=2;i<N;++i){
if(trio[i-2] == duo[i-1] + duo[i-2]){
greater = !greater;
}
arr[i] = arr[i-1] + duo[i-1] * ((int)greater * 2 - 1);
}
int maxi = 0, mini = 0;
int maxpos = 0, minpos = 0;
for(int i=1;i<N;++i){
if(arr[i] > maxi){
maxi = arr[i];
maxpos = i;
}
if(arr[i] < mini){
mini = arr[i];
minpos = i;
}
}
if(minpos < maxpos){
for(int i=0;i<N;++i){
answer(i+1,arr[i]-mini + 1);
}
}
else{
for(int i=0;i<N;++i){
answer(i+1,maxi - arr[i] + 1);
}
}
}