#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int A[5001];
int pos[5001];
void solve(int N) {
int id;
int l = 1, r = N;
while(r - l >= 0) {
int mid = (l + r) >> 1;
if (query(mid, N) != N - 1) {
id = mid - 1;
r = mid - 1;
} else {
l = mid + 1;
}
}
A[id] = 1;
pos[1] = id;
if (id > 1) {
A[id - 1] = 1 + query(id - 1, id);
pos[A[id - 1]] = id - 1;
}
A[id + 1] = 1 + query(id, id + 1);
pos[A[id + 1]] = id + 1;
for (int j = id - 2; j >= 1; j--) {
int dif = query(j, j + 1), sgn;
if (A[j + 1] + dif > N || pos[A[j + 1] + dif]) sgn = -1;
else if (A[j + 1] - dif <= 0 || pos[A[j + 1] - dif]) sgn = 1;
else if (max({A[j + 1] + dif, A[j + 1], A[j + 2]}) - min({A[j + 1] + dif, A[j + 1], A[j + 2]}) == query(j, j + 2)) sgn = 1;
else sgn = -1;
A[j] = A[j + 1] + sgn * dif;
pos[A[j]] = j;
}
for (int j = id + 2; j <= N; j++) {
int dif = query(j - 1, j), sgn;
if (A[j - 1] + dif > N || pos[A[j - 1] + dif]) sgn = -1;
else if (A[j - 1] - dif <= 0 || pos[A[j - 1] - dif]) sgn = 1;
else if (max({A[j - 1] + dif, A[j - 1], A[j - 2]}) - min({A[j - 1] + dif, A[j - 1], A[j - 2]}) == query(j - 2, j)) sgn = 1;
else sgn = -1;
A[j] = A[j - 1] + sgn * dif;
pos[A[j]] = j;
}
for (int i = 1; i <= N; i++) {
answer(pos[i], i);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:21:30: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
21 | A[id - 1] = 1 + query(id - 1, id);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
376 KB |
Output is correct |
19 |
Correct |
19 ms |
384 KB |
Output is correct |
20 |
Correct |
20 ms |
384 KB |
Output is correct |
21 |
Correct |
19 ms |
384 KB |
Output is correct |
22 |
Correct |
12 ms |
384 KB |
Output is correct |
23 |
Correct |
16 ms |
384 KB |
Output is correct |
24 |
Correct |
15 ms |
256 KB |
Output is correct |
25 |
Correct |
9 ms |
384 KB |
Output is correct |
26 |
Correct |
21 ms |
384 KB |
Output is correct |
27 |
Correct |
21 ms |
376 KB |
Output is correct |
28 |
Correct |
18 ms |
384 KB |
Output is correct |
29 |
Correct |
16 ms |
380 KB |
Output is correct |
30 |
Correct |
18 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
3 ms |
256 KB |
Output is correct |
17 |
Correct |
7 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
376 KB |
Output is correct |
19 |
Correct |
19 ms |
384 KB |
Output is correct |
20 |
Correct |
20 ms |
384 KB |
Output is correct |
21 |
Correct |
19 ms |
384 KB |
Output is correct |
22 |
Correct |
12 ms |
384 KB |
Output is correct |
23 |
Correct |
16 ms |
384 KB |
Output is correct |
24 |
Correct |
15 ms |
256 KB |
Output is correct |
25 |
Correct |
9 ms |
384 KB |
Output is correct |
26 |
Correct |
21 ms |
384 KB |
Output is correct |
27 |
Correct |
21 ms |
376 KB |
Output is correct |
28 |
Correct |
18 ms |
384 KB |
Output is correct |
29 |
Correct |
16 ms |
380 KB |
Output is correct |
30 |
Correct |
18 ms |
384 KB |
Output is correct |
31 |
Correct |
43 ms |
384 KB |
Output is correct |
32 |
Correct |
33 ms |
504 KB |
Output is correct |
33 |
Correct |
64 ms |
504 KB |
Output is correct |
34 |
Correct |
48 ms |
384 KB |
Output is correct |
35 |
Correct |
83 ms |
384 KB |
Output is correct |
36 |
Correct |
53 ms |
384 KB |
Output is correct |
37 |
Correct |
78 ms |
632 KB |
Output is correct |
38 |
Correct |
27 ms |
384 KB |
Output is correct |
39 |
Correct |
50 ms |
528 KB |
Output is correct |
40 |
Correct |
93 ms |
384 KB |
Output is correct |
41 |
Correct |
49 ms |
516 KB |
Output is correct |
42 |
Correct |
47 ms |
384 KB |
Output is correct |
43 |
Correct |
47 ms |
504 KB |
Output is correct |
44 |
Correct |
49 ms |
504 KB |
Output is correct |
45 |
Correct |
62 ms |
384 KB |
Output is correct |
46 |
Correct |
58 ms |
384 KB |
Output is correct |
47 |
Correct |
66 ms |
512 KB |
Output is correct |
48 |
Correct |
62 ms |
504 KB |
Output is correct |
49 |
Correct |
63 ms |
384 KB |
Output is correct |
50 |
Correct |
61 ms |
512 KB |
Output is correct |
51 |
Correct |
59 ms |
384 KB |
Output is correct |
52 |
Correct |
60 ms |
384 KB |
Output is correct |
53 |
Correct |
61 ms |
384 KB |
Output is correct |
54 |
Correct |
56 ms |
504 KB |
Output is correct |
55 |
Correct |
66 ms |
384 KB |
Output is correct |
56 |
Correct |
65 ms |
504 KB |
Output is correct |
57 |
Correct |
71 ms |
384 KB |
Output is correct |
58 |
Correct |
79 ms |
504 KB |
Output is correct |
59 |
Correct |
55 ms |
504 KB |
Output is correct |
60 |
Correct |
61 ms |
528 KB |
Output is correct |