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;
const int N = 5001;
static int A[N];
int n, d[N], d2[N], dir[N], res[N];
bool check_res() {
int mnpos = -1, mxpos = -1;
for(int i = 1; i <= n; i++) {
if(mnpos == -1 || res[mnpos] > res[i]) mnpos = i;
if(mxpos == -1 || res[mxpos] < res[i]) mxpos = i;
}
assert(mnpos != -1 && mxpos != -1 && mnpos != mxpos);
return mnpos < mxpos;
}
void bye() {
int mn = *min_element(res+1, res+n+1);
for(int i = 1; i <= n; i++) answer(i, res[i]-mn+1);
}
void calc() {
for(int i = 1; i <= n-1; i++) {
if(d[i] + d[i+1] != d2[i]) dir[i+1] = dir[i] ^ 1;
else dir[i+1] = dir[i];
}
for(int i = 2, curr = 0; i <= n; i++) {
if(dir[i-1] == 0) curr += d[i-1];
else res[i] = curr -= d[i-1];
res[i] = curr;
}
}
void solve(int _n) {
n = _n;
if(n == 1) {
answer(1, 1);
return;
}
if(n == 2) {
answer(1, 1);
answer(2, 2);
return;
}
for(int i = 1; i <= n-1; i++) d[i] = query(i, i+1);
for(int i = 1; i <= n-2; i++) d2[i] = query(i, i+2);
dir[1] = 0;
calc();
if(check_res()) {
bye();
return;
}
dir[1] = 1;
calc();
assert(check_res());
bye();
}
Compilation message (stderr)
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[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... |