# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
540434 | krit3379 | 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<bits/stdc++.h>
using namespace std;
#define N 5005
int a[N],b[N],ans[N];
void solve(int n){
int i,mi=0,ma=0,pmi=1,pma=1;
for(i=1;i<n;i++){
a[i]=query(i,i+1);
if(i!=n-1)b[i]=query(i,i+2);
}
for(i=1;i<n-1;i++){
if(b[i]!=abs(a[i])+a[i+1]&&a[i]>0)a[i+1]*=-1;
else if(b[i]==abs(a[i])+a[i+1]&&a[i]<0)a[i+1]*=-1;
}
ans[1]=0;
for(i=1;i<n;i++){
ans[i+1]+=ans[i]+a[i];
if(ans[i+1]<mi)mi=ans[i+1],pmi=i+1;
if(ans[i+1]>ma)ma=ans[i+1],pma=i+1;
}
for(i=1;i<=n;i++)ans[i]-=mi-1;
if(pmi<pma)for(i=1;i<=n;i++)answer(i,ans[i]);
else for(i=1;i<=n;i++)answer(i,n-ans[i]+1);
return ;
}