This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef A
#include "xylophone.h"
#endif
#include <bits/stdc++.h>
using namespace std;
const int nax=5e3+3;
int d[nax],t[nax];
int m[nax];
int p[nax];
void solve(int N) {
for(int i=0;i<N-1;i++)d[i]=query(i,i+1);
for(int i=0;i<N-2;i++)t[i]=query(i,i+2);
m[0]=d[0];
if(t[0]==d[0]+d[1])m[1]=d[1];
else m[1]=-d[1];
for(int i=1;i<N-2;i++){
int s=m[i]/abs(m[i]);
if(t[i]==d[i]+d[i+1])m[i+1]=s*d[i+1];
else m[i+1]=-s*d[i+1];
}
for(int i=1;i<N;i++)p[i]=p[i-1]+m[i-1];
int mini=*min_element(p,p+N);
for(int i=0;i<N;i++)p[i]+=-mini+1;
bool flag=false;
bool uno=false;
for(int i=0;i<N;i++){
if(p[i]==1)uno=true;
if(p[i]>N)flag=true;
if(p[i]==N&&!uno)flag=true;
}
if(!flag){
for(int i=0;i<N;i++)answer(i,p[i]);
return;
}
for(int i=1;i<N;i++)p[i]=p[i-1]-m[i-1];
mini=*min_element(p,p+N);
for(int i=0;i<N;i++)p[i]+=-mini+1;
for(int i=0;i<N;i++)answer(i,p[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |