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;
int ans[5005];
void solve(int N) {
int x = 2,prev= 0 ;
while(query(x, N) == N - 1)x++;
ans[x-1] = 1;
for(int i=x-2;i>=1;i--){
int y = query(i, i+1);
if(i == x-2)ans[i] = y + 1;
else{
if(ans[i+1] -y <= 1)ans[i] = ans[i+1] + y;
else if(ans[i+1] + y >= N)ans[i] = ans[i+1] - y;
else{
int y2 = query(i, i+2);
if(y2 != prev){
if(ans[i+1] + y == min(ans[i+1] ,ans[i+2]) + y2)ans[i] = ans[i+1] + y;
else ans[i] = ans[i+1] - y;
}
else{
if(ans[i+1] > ans[i+2])ans[i]=ans[i+1] -y;
else ans[i] = ans[i+1] + y;
}
}
}
prev = y;
}
prev = 0;
for(int i=x;i<=N;i++){
int y = query(i-1, i);
if(i == x)ans[i] = y + 1;
else{
if(ans[i-1] -y <= 1)ans[i] = ans[i-1] + y;
else if(ans[i-1] + y >= N)ans[i] = ans[i-1] - y;
else{
int y2 = query(i-2, i);
if(y2 != prev){
if(ans[i-1] + y == min(ans[i-1], ans[i-2]) + y2)ans[i] = ans[i-1] + y;
else ans[i] = ans[i-1] - y;
}
else{
if(ans[i-1] > ans[i-2])ans[i]=ans[i-1] -y;
else ans[i] = ans[i-1] + y;
}
}
}
prev = y;
}
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... |