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>
#define f first
#define s second
#define pb push_back
using namespace std;
const int NN = 5005;
int le,ri,mid,ans,a[NN],val[NN],vl1,n;
void solve(int N) {
n = N;
le = 2;
ri = n;
while (le <= ri) {
mid = (le + ri) / 2;
if (query(1,mid) == n - 1) {
ri = mid - 1;
ans = mid;
} else le = mid + 1;
}
a[ans] = n;
for (int i = ans + 1; i <= n; i++) {
if (i == ans + 1) {
val[i - 1] = query(i-1,i);
a[i] = a[ans] - val[i - 1];
continue;
}
val[i - 1] = query(i - 1, i);
vl1 = query(i - 2, i);
if (val[i - 2] + val[i - 1] == vl1) {
a[i] = (a[i - 2] > a[i - 1] ? (a[i - 1] - val[i - 1]) : (a[i - 1] + val[i - 1]));
} else
a[i] = (a[i - 2] > a[i - 1] ? (a[i - 1] + val[i - 1]) : (a[i - 1] - val[i - 1]));
}
for (int i = ans - 1; i >= 1; i--) {
if (i == ans - 1) {
val[i] = query(i, i + 1);
a[i] = a[ans] - val[i];
continue;
}
val[i] = query(i, i + 1);
vl1 = query(i, i + 2);
if (vl1 == val[i] + val[i + 1]) {
a[i] = (a[i + 2] > a[i + 1] ? (a[i + 1] - val[i]) : (a[i + 1] + val[i]));
} else a[i] = (a[i + 2] > a[i + 1] ? (a[i + 1] + val[i]) : (a[i + 1] - val[i]));
}
for (int i = 1; i <= n; i++) {
answer(i,a[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... |