#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int ans[5005];
void solve(int N) {
int l, r;
int bl = 1, br = N;
while (bl <= br) {
int m = bl + br >> 1;
if (query(m, N) != N - 1) br = m - 1;
else bl = m+1;
}
l = br;
bl = 1, br = N;
while (bl <= br) {
int m = bl + br >> 1;
if (query(1, m) != N - 1) bl = m + 1;
else br = m-1;
}
r = bl;
ans[l] = 1;
ans[l + 1] = ans[l] + query(l, l + 1);
if (l - 1 > 0) ans[l - 1] = ans[l] + query(l - 1, l);
ans[r] = N;
ans[r - 1] = ans[r] - query(r - 1, r);
if (r + 1 <= N) ans[r + 1] = ans[r] - query(r, r + 1);
for (int i = l - 1; i > 1; --i) {
int diff = query(i - 1, i);
if (diff + abs(ans[i] - ans[i + 1]) == query(i - 1, i + 1)) {
if (ans[i] < ans[i + 1]) ans[i - 1] = ans[i] - diff;
else ans[i - 1] = ans[i] + diff;
}
else {
if (ans[i] < ans[i + 1]) ans[i - 1] = ans[i] + diff;
else ans[i - 1] = ans[i] - diff;
}
}
for (int i = r - 1; i > l + 2; --i) {
int diff = query(i - 1, i);
if (diff + abs(ans[i] - ans[i + 1]) == query(i - 1, i + 1)) {
if (ans[i] < ans[i + 1]) ans[i - 1] = ans[i] - diff;
else ans[i - 1] = ans[i] + diff;
}
else {
if (ans[i] < ans[i + 1]) ans[i - 1] = ans[i] + diff;
else ans[i - 1] = ans[i] - diff;
}
}
for (int i = r + 1; i < N; ++i) {
int diff = query(i, i + 1);
if (diff + abs(ans[i] - ans[i - 1]) == query(i - 1, i + 1)) {
if (ans[i - 1] > ans[i]) ans[i + 1] = ans[i] - diff;
else ans[i + 1] = ans[i] + diff;
}
else {
if (ans[i - 1] > ans[i]) ans[i + 1] = ans[i] + diff;
else ans[i + 1] = ans[i] - diff;
}
}
for (int i = 1; i <= N; i++) {
answer(i, ans[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:14:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | int m = bl + br >> 1;
| ~~~^~~~
xylophone.cpp:22:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | int m = bl + br >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
208 KB |
Output is correct |
18 |
Correct |
10 ms |
208 KB |
Output is correct |
19 |
Correct |
21 ms |
208 KB |
Output is correct |
20 |
Correct |
12 ms |
296 KB |
Output is correct |
21 |
Correct |
20 ms |
288 KB |
Output is correct |
22 |
Correct |
14 ms |
288 KB |
Output is correct |
23 |
Correct |
19 ms |
208 KB |
Output is correct |
24 |
Correct |
14 ms |
208 KB |
Output is correct |
25 |
Correct |
18 ms |
292 KB |
Output is correct |
26 |
Correct |
15 ms |
208 KB |
Output is correct |
27 |
Correct |
15 ms |
292 KB |
Output is correct |
28 |
Correct |
19 ms |
296 KB |
Output is correct |
29 |
Correct |
20 ms |
208 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
9 ms |
208 KB |
Output is correct |
18 |
Correct |
10 ms |
208 KB |
Output is correct |
19 |
Correct |
21 ms |
208 KB |
Output is correct |
20 |
Correct |
12 ms |
296 KB |
Output is correct |
21 |
Correct |
20 ms |
288 KB |
Output is correct |
22 |
Correct |
14 ms |
288 KB |
Output is correct |
23 |
Correct |
19 ms |
208 KB |
Output is correct |
24 |
Correct |
14 ms |
208 KB |
Output is correct |
25 |
Correct |
18 ms |
292 KB |
Output is correct |
26 |
Correct |
15 ms |
208 KB |
Output is correct |
27 |
Correct |
15 ms |
292 KB |
Output is correct |
28 |
Correct |
19 ms |
296 KB |
Output is correct |
29 |
Correct |
20 ms |
208 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
31 |
Correct |
31 ms |
288 KB |
Output is correct |
32 |
Correct |
59 ms |
288 KB |
Output is correct |
33 |
Correct |
60 ms |
296 KB |
Output is correct |
34 |
Incorrect |
85 ms |
208 KB |
Wrong Answer [2] |
35 |
Halted |
0 ms |
0 KB |
- |