#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 != abs(a[i]) + abs(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 |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
692 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
13 |
Correct |
3 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
692 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
13 |
Correct |
3 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
5 ms |
312 KB |
Output is correct |
17 |
Correct |
10 ms |
720 KB |
Output is correct |
18 |
Correct |
13 ms |
464 KB |
Output is correct |
19 |
Correct |
21 ms |
1448 KB |
Output is correct |
20 |
Correct |
19 ms |
2100 KB |
Output is correct |
21 |
Correct |
35 ms |
3876 KB |
Output is correct |
22 |
Correct |
21 ms |
2248 KB |
Output is correct |
23 |
Correct |
15 ms |
208 KB |
Output is correct |
24 |
Correct |
21 ms |
8116 KB |
Output is correct |
25 |
Correct |
21 ms |
308 KB |
Output is correct |
26 |
Correct |
14 ms |
3144 KB |
Output is correct |
27 |
Correct |
19 ms |
5064 KB |
Output is correct |
28 |
Correct |
22 ms |
1456 KB |
Output is correct |
29 |
Correct |
20 ms |
1576 KB |
Output is correct |
30 |
Correct |
17 ms |
2232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
3 ms |
692 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
464 KB |
Output is correct |
13 |
Correct |
3 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
464 KB |
Output is correct |
16 |
Correct |
5 ms |
312 KB |
Output is correct |
17 |
Correct |
10 ms |
720 KB |
Output is correct |
18 |
Correct |
13 ms |
464 KB |
Output is correct |
19 |
Correct |
21 ms |
1448 KB |
Output is correct |
20 |
Correct |
19 ms |
2100 KB |
Output is correct |
21 |
Correct |
35 ms |
3876 KB |
Output is correct |
22 |
Correct |
21 ms |
2248 KB |
Output is correct |
23 |
Correct |
15 ms |
208 KB |
Output is correct |
24 |
Correct |
21 ms |
8116 KB |
Output is correct |
25 |
Correct |
21 ms |
308 KB |
Output is correct |
26 |
Correct |
14 ms |
3144 KB |
Output is correct |
27 |
Correct |
19 ms |
5064 KB |
Output is correct |
28 |
Correct |
22 ms |
1456 KB |
Output is correct |
29 |
Correct |
20 ms |
1576 KB |
Output is correct |
30 |
Correct |
17 ms |
2232 KB |
Output is correct |
31 |
Correct |
51 ms |
8492 KB |
Output is correct |
32 |
Correct |
73 ms |
18392 KB |
Output is correct |
33 |
Correct |
120 ms |
32944 KB |
Output is correct |
34 |
Correct |
124 ms |
49332 KB |
Output is correct |
35 |
Correct |
146 ms |
47504 KB |
Output is correct |
36 |
Correct |
65 ms |
336 KB |
Output is correct |
37 |
Correct |
252 ms |
98228 KB |
Output is correct |
38 |
Correct |
99 ms |
328 KB |
Output is correct |
39 |
Correct |
85 ms |
39212 KB |
Output is correct |
40 |
Correct |
101 ms |
11700 KB |
Output is correct |
41 |
Correct |
135 ms |
30128 KB |
Output is correct |
42 |
Correct |
153 ms |
308 KB |
Output is correct |
43 |
Correct |
267 ms |
98276 KB |
Output is correct |
44 |
Correct |
96 ms |
296 KB |
Output is correct |
45 |
Correct |
91 ms |
5672 KB |
Output is correct |
46 |
Correct |
83 ms |
12084 KB |
Output is correct |
47 |
Correct |
77 ms |
568 KB |
Output is correct |
48 |
Correct |
96 ms |
10676 KB |
Output is correct |
49 |
Correct |
166 ms |
48048 KB |
Output is correct |
50 |
Correct |
147 ms |
50608 KB |
Output is correct |
51 |
Correct |
62 ms |
1208 KB |
Output is correct |
52 |
Correct |
184 ms |
64180 KB |
Output is correct |
53 |
Correct |
152 ms |
34356 KB |
Output is correct |
54 |
Correct |
105 ms |
13264 KB |
Output is correct |
55 |
Correct |
122 ms |
6836 KB |
Output is correct |
56 |
Correct |
90 ms |
26168 KB |
Output is correct |
57 |
Correct |
118 ms |
18612 KB |
Output is correct |
58 |
Correct |
196 ms |
83500 KB |
Output is correct |
59 |
Correct |
87 ms |
24620 KB |
Output is correct |
60 |
Correct |
133 ms |
38072 KB |
Output is correct |