# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701591 | Alexabcde1 | 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>
#define f first
#define s second
using namespace std;
long long n,i,j,ress[5005][5005],resp,neg,minn,maxx;
long long ans[5005];
long long res(long long x,long long y){
if (ress[x][y]!=0) return ress[x][y];
ress[x][y]=query(x,y);
return ress[x][y];
}
void solve(int n){
if (n==2){
cout<<"A 1 2"<<endl;
return 0;
}
ans[1]=0;
for (i=1;i<=n-2;i++){
if (res(i,i+1)+res(i+1,i+2)==res(i,i+2)){
ans[i+1]=ans[i]+res(i,i+1);
ans[i+2]=ans[i]+res(i,i+2);
if (ans[i+2]>=n){
ans[i+1]=ans[i]-res(i,i+1);
ans[i+2]=ans[i]-res(i,i+2);
}
}
else {
ans[i+1]=ans[i]+res(i,i+1);
ans[i+2]=ans[i+1]-res(i+1,i+2);
if (ans[i+1]>=n){
ans[i+1]=ans[i]-res(i,i+1);
ans[i+2]=ans[i+1]+res(i+1,i+2);
}
}
if (ans[i+2]<0 || ans[i+1]<0) neg=1;
}
maxx=1; minn=1;
for (i=2;i<=n;i++){
if (ans[i]>ans[maxx]) maxx=i;
if (ans[i]<ans[minn]) minn=i;
}
if (maxx<minn) {
for (i=1;i<=n;i++){
ans[i]=-ans[i];
}
}
minn=ans[1];
for (i=2;i<=n;i++){
minn=min(minn,ans[i]);
}
minn=-minn+1;
for (i=1;i<=n;i++) answer(i,ans[i]+minn);
}