#include "xylophone.h"
#include <vector>
using namespace std;
void solve(int n) {
vector<int> ans(n+1);
vector<bool> used(n+1);
int l = 1, r = n;
int first = 0;
while (l <= r){
int mid = (l + r) / 2;
if (query(mid, n) == n-1){
first = mid;
l = mid + 1;
} else r = mid - 1;
}
ans[first] = 1;
used[1] = true;
for (int i = first - 1; i > 0; --i){
int k = query(i, i+1);
int x = ans[i+1] + k;
int y = ans[i+1] - k;
if (y < 1 || used[y]) ans[i] = x, used[x] = true;
else if (x > n || used[x]) ans[i] = y, used[y] = true;
else{
int a = query(i, i+2);
int mn = min(ans[i+1], ans[i+2]);
int mx = max(ans[i+1], ans[i+2]);
if (a == mx - mn && x > mn && x < mx) ans[i] = x, used[x] = true;
else if (a == mx - mn) ans[i] = y, used[y] = true;
else if (a == max(mx, x) - min(mn, x)) ans[i] = x, used[x] = true;
else ans[i] = y, used[y] = true;
}
}
for (int i = first + 1; i <= n; ++i){
int k = query(i-1, i);
int x = ans[i-1] + k;
int y = ans[i-1] - k;
if (y < 1 || used[y]) ans[i] = x, used[x] = true;
else if (x > n || used[x]) ans[i] = y, used[y] = true;
else{
int a = query(i-2, i);
int mn = min(ans[i-1], ans[i-2]);
int mx = max(ans[i-1], ans[i-2]);
if (a == mx - mn && x > mn && x < mx) ans[i] = x, used[x] = true;
else if (a == mx - mn) ans[i] = y, used[y] = true;
else if (a == max(mx, x) - min(mn, x)) ans[i] = x, used[x] = true;
else ans[i] = y, used[y] = true;
}
}
for (int i = 1; i <= n; ++i) {
answer(i, ans[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
3 ms |
200 KB |
Output is correct |
17 |
Correct |
8 ms |
200 KB |
Output is correct |
18 |
Correct |
7 ms |
288 KB |
Output is correct |
19 |
Correct |
17 ms |
200 KB |
Output is correct |
20 |
Correct |
8 ms |
280 KB |
Output is correct |
21 |
Correct |
16 ms |
200 KB |
Output is correct |
22 |
Correct |
13 ms |
200 KB |
Output is correct |
23 |
Correct |
10 ms |
200 KB |
Output is correct |
24 |
Correct |
9 ms |
200 KB |
Output is correct |
25 |
Correct |
14 ms |
200 KB |
Output is correct |
26 |
Correct |
16 ms |
200 KB |
Output is correct |
27 |
Correct |
17 ms |
200 KB |
Output is correct |
28 |
Correct |
16 ms |
200 KB |
Output is correct |
29 |
Correct |
15 ms |
200 KB |
Output is correct |
30 |
Correct |
12 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Correct |
2 ms |
200 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
2 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
200 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
3 ms |
200 KB |
Output is correct |
17 |
Correct |
8 ms |
200 KB |
Output is correct |
18 |
Correct |
7 ms |
288 KB |
Output is correct |
19 |
Correct |
17 ms |
200 KB |
Output is correct |
20 |
Correct |
8 ms |
280 KB |
Output is correct |
21 |
Correct |
16 ms |
200 KB |
Output is correct |
22 |
Correct |
13 ms |
200 KB |
Output is correct |
23 |
Correct |
10 ms |
200 KB |
Output is correct |
24 |
Correct |
9 ms |
200 KB |
Output is correct |
25 |
Correct |
14 ms |
200 KB |
Output is correct |
26 |
Correct |
16 ms |
200 KB |
Output is correct |
27 |
Correct |
17 ms |
200 KB |
Output is correct |
28 |
Correct |
16 ms |
200 KB |
Output is correct |
29 |
Correct |
15 ms |
200 KB |
Output is correct |
30 |
Correct |
12 ms |
200 KB |
Output is correct |
31 |
Correct |
24 ms |
200 KB |
Output is correct |
32 |
Correct |
39 ms |
268 KB |
Output is correct |
33 |
Correct |
27 ms |
284 KB |
Output is correct |
34 |
Correct |
52 ms |
296 KB |
Output is correct |
35 |
Correct |
54 ms |
320 KB |
Output is correct |
36 |
Correct |
52 ms |
280 KB |
Output is correct |
37 |
Correct |
26 ms |
280 KB |
Output is correct |
38 |
Correct |
59 ms |
200 KB |
Output is correct |
39 |
Correct |
63 ms |
292 KB |
Output is correct |
40 |
Correct |
70 ms |
280 KB |
Output is correct |
41 |
Correct |
35 ms |
292 KB |
Output is correct |
42 |
Correct |
39 ms |
200 KB |
Output is correct |
43 |
Correct |
61 ms |
280 KB |
Output is correct |
44 |
Correct |
58 ms |
280 KB |
Output is correct |
45 |
Correct |
73 ms |
280 KB |
Output is correct |
46 |
Correct |
57 ms |
276 KB |
Output is correct |
47 |
Correct |
79 ms |
288 KB |
Output is correct |
48 |
Correct |
82 ms |
200 KB |
Output is correct |
49 |
Correct |
63 ms |
320 KB |
Output is correct |
50 |
Correct |
57 ms |
284 KB |
Output is correct |
51 |
Correct |
61 ms |
276 KB |
Output is correct |
52 |
Correct |
71 ms |
276 KB |
Output is correct |
53 |
Correct |
78 ms |
296 KB |
Output is correct |
54 |
Correct |
42 ms |
276 KB |
Output is correct |
55 |
Correct |
73 ms |
284 KB |
Output is correct |
56 |
Correct |
42 ms |
288 KB |
Output is correct |
57 |
Correct |
67 ms |
280 KB |
Output is correct |
58 |
Correct |
77 ms |
320 KB |
Output is correct |
59 |
Correct |
68 ms |
280 KB |
Output is correct |
60 |
Correct |
61 ms |
292 KB |
Output is correct |