#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int ar[MAXN];
void solve(int n) {
memset(ar, -1, sizeof ar);
ar[1] = 0;
ar[2] = query(1, 2);
for (int i = 2; i + 1 <= n; i++) {
int a = ar[i], b = ar[i - 1];
int one = query(i, i + 1);
int two = query(i - 1, i + 1);
if (a < b) {
if (a - one + two == b)
ar[i + 1] = a - one;
else
ar[i + 1] = a + one;
} else {
if (a + one - two == b)
ar[i + 1] = a + one;
else
ar[i + 1] = a - one;
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (abs(ar[i] - ar[j]) != n - 1)
continue;
int add = 1 - min(ar[i], ar[j]);
for (int k = 1; k <= n; k++) {
ar[k] += add;
}
if (ar[i] > ar[j]) {
for (int k = 1; k <= n; k++) {
ar[k] = n - ar[k];
}
}
}
}
for (int i = 1; i <= n; i++) {
answer(i, ar[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
308 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Incorrect |
5 ms |
508 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
308 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Incorrect |
5 ms |
508 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
308 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
460 KB |
Output is correct |
5 |
Incorrect |
5 ms |
508 KB |
Wrong Answer [7] |
6 |
Halted |
0 ms |
0 KB |
- |