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<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include "xylophone.h"
using namespace std;
static const int N_MAX = 5000;
static const int Q_MAX = 10000;
static int N;
static int A[N_MAX];
static bool used[N_MAX];
static int query_c;
static int answer_c;
void solve(int N) {
vector<int> v(N+1, 0);
int l = 2, r = N;
int rez = -1;
while(l<=r){
int mid = (l+r)/2;
if(query(1, mid)!=N-1){
l = mid+1;
} else{
rez = mid;
r = mid-1;
}
}
answer(rez, N);
v[rez] = N;
if(rez!=1){
int x = N-query(rez-1, rez);
answer(rez-1, x);
v[rez-1] = x;
}
if(rez!=N){
int x = N-query(rez, rez+1);
answer(rez+1, x);
v[rez+1] = x;
}
for(int i = rez-2;i>=1;i--){
int d1 = query(i, i+1), d2 = query(i, i+2);
int ans = 0;
if(v[i+1]>v[i+2]){
if(d1+v[i+1]-v[i+2]==d2) ans = v[i+1]+d1;
else ans = v[i+1]-d1;
} else{
if(d1+v[i+2]-v[i+1]==d2) ans = v[i+1]-d1;
else ans = v[i+1]+d1;
}
answer(i, ans);
v[i] = ans;
}
for(int i = rez+2;i<=N;i++){
int d1 = query(i-1, i), d2 = query(i-2, i);
int ans = 0;
if(v[i-1]>v[i-2]){
if(d1+v[i-1]-v[i-2]==d2) ans = v[i-1]+d1;
else ans = v[i-1]-d1;
} else{
if(d1+v[i-2]-v[i-1]==d2) ans = v[i-1]-d1;
else ans = v[i-1]+d1;
}
answer(i, ans);
v[i] = ans;
}
}
Compilation message (stderr)
xylophone.cpp:14:12: warning: 'answer_c' defined but not used [-Wunused-variable]
14 | static int answer_c;
| ^~~~~~~~
xylophone.cpp:13:12: warning: 'query_c' defined but not used [-Wunused-variable]
13 | static int query_c;
| ^~~~~~~
xylophone.cpp:12:13: warning: 'used' defined but not used [-Wunused-variable]
12 | static bool used[N_MAX];
| ^~~~
xylophone.cpp:11:12: warning: 'A' defined but not used [-Wunused-variable]
11 | static int A[N_MAX];
| ^
xylophone.cpp:10:12: warning: 'N' defined but not used [-Wunused-variable]
10 | static int N;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |