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 n, root, a[5008], dis[5008][5008];
void solve(int N) {
n = N;
for (int i = 1; i < n; i++)
a[i] = query(i, i + 1);
for (int i = 1, j = 1; i + 2 <= n; i++){
int tmp = query(i, i + 2);
if (tmp != a[i] + a[i + 1])
j *= -1;
a[i + 1] *= j;
}
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = i + 1; j <= n; j++){
dis[i][j] = dis[i][j - 1] + a[j - 1];
if (dis[i][j] > 0)
cnt++;
}
for (int j = i - 1; j > 0; j--){
dis[i][j] = -dis[j][i];
if (dis[i][j] > 0)
cnt++;
}
if (!cnt || cnt + 1 == n){
root = i;
break;
}
}
for (int i = 1; i <= n; i++)
answer(i, abs(dis[root][i]) + 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |