#include "xylophone.h"
#include <bits/stdc++.h>
void solve(int n) {
std::ios::sync_with_stdio(0); std::cin.tie(0);
std::vector <int> d1, d2, ans(n);
for (int i = 0; i < n - 1; i++) {
d1.push_back(query(i + 1, i + 2));
if (i < n - 2) d2.push_back(query(i + 1, i + 3));
}
ans[0] = 0;
ans[1] = d1[0];
for (int i = 2; i < n; i++) {
ans[i] = ans[i - 1];
if (d1[i - 2] + d1[i - 1] == d2[i - 2]) {
if(ans[i - 2] < ans[i - 1]) ans[i] += d1[i - 1];
else ans[i] -= d1[i - 1];
} else {
if (ans[i - 2] < ans[i - 1]) ans[i] -= d1[i - 1];
else ans[i] += d1[i - 1];
}
}
int l = 1 << 30;
for (int x : ans) l = std::min(l, x);
for (int& x : ans) x -= l - 1;
if (min_element(ans.begin(), ans.end()) > max_element(ans.begin(), ans.end())) {
for (int& x : ans) x = n - x + 1;
}
for (int i = 0; i < n; i++) answer(i + 1, ans[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
404 KB |
Output is correct |
18 |
Correct |
10 ms |
404 KB |
Output is correct |
19 |
Correct |
22 ms |
384 KB |
Output is correct |
20 |
Correct |
19 ms |
384 KB |
Output is correct |
21 |
Correct |
17 ms |
384 KB |
Output is correct |
22 |
Correct |
18 ms |
384 KB |
Output is correct |
23 |
Correct |
22 ms |
384 KB |
Output is correct |
24 |
Correct |
21 ms |
384 KB |
Output is correct |
25 |
Correct |
18 ms |
400 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
19 ms |
384 KB |
Output is correct |
28 |
Correct |
11 ms |
404 KB |
Output is correct |
29 |
Correct |
17 ms |
384 KB |
Output is correct |
30 |
Correct |
16 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
404 KB |
Output is correct |
18 |
Correct |
10 ms |
404 KB |
Output is correct |
19 |
Correct |
22 ms |
384 KB |
Output is correct |
20 |
Correct |
19 ms |
384 KB |
Output is correct |
21 |
Correct |
17 ms |
384 KB |
Output is correct |
22 |
Correct |
18 ms |
384 KB |
Output is correct |
23 |
Correct |
22 ms |
384 KB |
Output is correct |
24 |
Correct |
21 ms |
384 KB |
Output is correct |
25 |
Correct |
18 ms |
400 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
19 ms |
384 KB |
Output is correct |
28 |
Correct |
11 ms |
404 KB |
Output is correct |
29 |
Correct |
17 ms |
384 KB |
Output is correct |
30 |
Correct |
16 ms |
384 KB |
Output is correct |
31 |
Correct |
33 ms |
384 KB |
Output is correct |
32 |
Correct |
60 ms |
384 KB |
Output is correct |
33 |
Correct |
104 ms |
504 KB |
Output is correct |
34 |
Correct |
91 ms |
508 KB |
Output is correct |
35 |
Correct |
68 ms |
504 KB |
Output is correct |
36 |
Correct |
87 ms |
540 KB |
Output is correct |
37 |
Correct |
88 ms |
504 KB |
Output is correct |
38 |
Correct |
90 ms |
504 KB |
Output is correct |
39 |
Correct |
87 ms |
504 KB |
Output is correct |
40 |
Correct |
86 ms |
504 KB |
Output is correct |
41 |
Correct |
121 ms |
556 KB |
Output is correct |
42 |
Correct |
105 ms |
680 KB |
Output is correct |
43 |
Correct |
86 ms |
504 KB |
Output is correct |
44 |
Correct |
95 ms |
504 KB |
Output is correct |
45 |
Correct |
101 ms |
504 KB |
Output is correct |
46 |
Correct |
94 ms |
504 KB |
Output is correct |
47 |
Correct |
70 ms |
568 KB |
Output is correct |
48 |
Correct |
91 ms |
504 KB |
Output is correct |
49 |
Correct |
87 ms |
504 KB |
Output is correct |
50 |
Correct |
130 ms |
504 KB |
Output is correct |
51 |
Correct |
120 ms |
508 KB |
Output is correct |
52 |
Correct |
83 ms |
564 KB |
Output is correct |
53 |
Correct |
90 ms |
504 KB |
Output is correct |
54 |
Correct |
111 ms |
504 KB |
Output is correct |
55 |
Correct |
89 ms |
504 KB |
Output is correct |
56 |
Correct |
91 ms |
592 KB |
Output is correct |
57 |
Correct |
85 ms |
536 KB |
Output is correct |
58 |
Correct |
107 ms |
504 KB |
Output is correct |
59 |
Correct |
89 ms |
504 KB |
Output is correct |
60 |
Correct |
120 ms |
448 KB |
Output is correct |