# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
641885 | ivaziva | 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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define MAXN 5010
long long a[MAXN],d1[MAXN],d2[MAXN],e[MAXN];
void solve(long long n)
{
for (long long i=0;i<n-1;i++) d1[i]=query(i+1,i+2);
for (long long i=0;i<n-2;i++) d2[i]=query(i+1,i+3);
e[0]=d1[0];
for (long long i=1;i<n-1;i++)
{
e[i]=d1[i];
if (e[i-1]<0)
{
e[i]=-e[i];
}
if (d1[i-1]+d1[i]!=d2[i-1])
{
e[i]=-e[i];
}
}
long long mn=0,mni=0,cur=0;
for (long long i=1;i<n;i++)
{
cur+=e[i-1];
if (cur<e[i-1])
{
mni=i;
mn=cur;
}
}
cur=0;
for (long long i=mni;i<n;i++)
{
a[i]=cur;
cur+=e[i-1];
}
cur=0;
for (long long i=mni;i>=0;i--)
{
cur-=e[i];
a[i]=cur;
}
long long pos=0;
while (a[pos]!=n-1) pos++;
if (mni>pos)
{
for (long long i=0;i<n;i++) a[i]=n-1-a[i];
}
for (long long i=0;i<n;i++) answer(i+1,a[i]+1);
}