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>
#pragma GCC optimize("Ofast")
using namespace std;
static int A[5000];
int dva[5005];
int tri[5005];
int res[5005];
int nadji(int a, int b, int c){
return max(abs(a-c), max(abs(a-b), abs(b-c)));
}
void solve(int N) {
if(N == 1){
answer(1, 1);
return;
}
for(int i=1; i<N; i++){
dva[i] = query(i, i+1);
}
for(int i=1; i<N-1; i++){
tri[i] = query(i, i+2);
}
res[2] = dva[1];
for(int i=3; i<=N; i++){
if(nadji(res[i-2], res[i-1], dva[i-1] + res[i-1]) == tri[i-2]) res[i] = dva[i-1] + res[i-1];
else res[i] = res[i-1] - dva[i-1];
}
int mn = 0;
for(int i=1; i<=N; i++){
mn = min(mn, res[i]);
}
for(int i=1; i<=N; i++){
res[i] += 1-mn;
}
int b1 = 0, bn = 0;
for(int i=1; i<=N; i++){
if(res[i] == 1) b1 = i;
else if(res[i] == N) bn = i;
}
if(b1 > bn){
for(int i=1; i<=N; i++) res[i] = N-res[i]+1;
}
for(int i=1; i<=N; i++){
answer(i, res[i]);
}
}
Compilation message (stderr)
xylophone.cpp:6:12: warning: 'A' defined but not used [-Wunused-variable]
6 | static int A[5000];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |