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"
static int ans[5010],diff1[5010],diff2[5010],mi,ma,miid,maid;
bool greater[5010];
void solve(int N) {
for(int i=1; i<N; i++){
diff1[i]=query(i,i+1);
if(i!=N-1){
diff2[i]=query(i,i+2);
}
}
ans[1]=1;
//greater=1, i<i+1;
for(int i=1; i<N; i++){
if(greater[i]){
ans[i+1]=ans[i]+diff1[i];
if(ans[i+1]>ma){
ma=ans[i+1];
maid=i+1;
}
}
else{
ans[i+1]=ans[i]-diff1[i];
if(ans[i+1]<mi){
mi=ans[i+1];
miid=i+1;
}
}
if(diff1[i+1]<diff2[i]){
greater[i+1]=greater[i];
}else{
greater[i+1]=!greater[i];
}
}
if(mi<1){
for(int i=1; i<=N; i++){
ans[i]+=i-mi;
}
}
if(miid>maid){
for(int i=1; i<=N; i++){
ans[i]=N+1-ans[i];
}
}
for(int i = 1; i <= N; i++) {
answer(i, ans[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... |