#include"xylophone.h"
#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ll long long
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int MAXN=5050;
int n,d2[MAXN],d3[MAXN],isSame[MAXN],p[MAXN];
void solve(int N){
n=N;
foru(i,1,n-1){
d2[i]=query(i,i+1);
}
foru(i,1,n-2){
d3[i]=query(i,i+2);
}
foru(i,2,n-1){
if(d2[i-1]+d2[i]==d3[i-1]) isSame[i]=1;
else isSame[i]=0;
}
/// initially, sign=-1
int sign=-1;
p[1]=0; p[2]=sign*d2[1];
foru(i,2,n-1){
if(!isSame[i]) sign*=-1;
p[i+1]=p[i]+sign*d2[i];
}
int mi=0;
foru(i,1,n) mini(mi,p[i]);
int pos1=-1, posn=-1;
foru(i,1,n){
p[i]=p[i]-mi+1;
if(p[i]==1) pos1=i;
if(p[i]==n) posn=i;
}
if(pos1<posn){
foru(i,1,n) answer(i,p[i]);
return;
}
/// try with sign=1
sign=1;
p[1]=0; p[2]=sign*d2[1];
foru(i,2,n-1){
if(!isSame[i]) sign*=-1;
p[i+1]=p[i]+sign*d2[i];
}
mi=0;
foru(i,1,n) mini(mi,p[i]);
pos1=-1, posn=-1;
foru(i,1,n){
p[i]=p[i]-mi+1;
if(p[i]==1) pos1=i;
if(p[i]==n) posn=i;
}
if(pos1<posn){
foru(i,1,n) answer(i,p[i]);
return;
}
assert(0); /// wtf is happening
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |