#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int N) {
vector<int> dif1;
vector<int> dif2;
for (int i = 0; i + 1 < N; i++) {
dif1.emplace_back(query(i + 1, i + 2));
}
for (int i = 0; i + 2 < N; i++) {
dif2.emplace_back(query(i + 1, i + 3));
}
vector<int> ans(N);
ans[0] = 0;
ans[1] = dif1[0];
for (int i = 2; i < N; i++) {
if (dif1[i - 2] + dif1[i - 1] == dif2[i - 2]) {
if (ans[i - 2] < ans[i - 1]) {
ans[i] = ans[i - 1] + dif1[i - 1];
} else {
ans[i] = ans[i - 1] - dif1[i - 1];
}
} else {
if (ans[i - 2] < ans[i - 1]) {
ans[i] = ans[i - 1] - dif1[i - 1];
} else {
ans[i] = ans[i - 1] + dif1[i - 1];
}
}
}
int mn = *min_element(begin(ans), end(ans));
for (int i = 0; i < N; i++) {
ans[i] -= mn - 1;
}
if (min_element(begin(ans), end(ans)) > max_element(begin(ans), end(ans))) {
for (int i = 0; i < N; i++) {
ans[i] = N - ans[i] + 1;
}
}
for (int i = 0; i < N; i++) {
answer(i + 1, ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
288 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 |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
288 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
288 KB |
Output is correct |
18 |
Correct |
16 ms |
376 KB |
Output is correct |
19 |
Correct |
24 ms |
376 KB |
Output is correct |
20 |
Correct |
18 ms |
380 KB |
Output is correct |
21 |
Correct |
22 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
376 KB |
Output is correct |
23 |
Correct |
19 ms |
376 KB |
Output is correct |
24 |
Correct |
18 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
376 KB |
Output is correct |
26 |
Correct |
17 ms |
376 KB |
Output is correct |
27 |
Correct |
17 ms |
376 KB |
Output is correct |
28 |
Correct |
18 ms |
384 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
20 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 |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
288 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
288 KB |
Output is correct |
18 |
Correct |
16 ms |
376 KB |
Output is correct |
19 |
Correct |
24 ms |
376 KB |
Output is correct |
20 |
Correct |
18 ms |
380 KB |
Output is correct |
21 |
Correct |
22 ms |
384 KB |
Output is correct |
22 |
Correct |
11 ms |
376 KB |
Output is correct |
23 |
Correct |
19 ms |
376 KB |
Output is correct |
24 |
Correct |
18 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
376 KB |
Output is correct |
26 |
Correct |
17 ms |
376 KB |
Output is correct |
27 |
Correct |
17 ms |
376 KB |
Output is correct |
28 |
Correct |
18 ms |
384 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
20 ms |
384 KB |
Output is correct |
31 |
Correct |
50 ms |
384 KB |
Output is correct |
32 |
Correct |
76 ms |
376 KB |
Output is correct |
33 |
Correct |
99 ms |
504 KB |
Output is correct |
34 |
Correct |
123 ms |
376 KB |
Output is correct |
35 |
Correct |
103 ms |
504 KB |
Output is correct |
36 |
Correct |
84 ms |
376 KB |
Output is correct |
37 |
Correct |
111 ms |
376 KB |
Output is correct |
38 |
Correct |
125 ms |
384 KB |
Output is correct |
39 |
Correct |
78 ms |
380 KB |
Output is correct |
40 |
Correct |
115 ms |
376 KB |
Output is correct |
41 |
Correct |
88 ms |
528 KB |
Output is correct |
42 |
Correct |
96 ms |
384 KB |
Output is correct |
43 |
Correct |
91 ms |
384 KB |
Output is correct |
44 |
Correct |
88 ms |
504 KB |
Output is correct |
45 |
Correct |
97 ms |
384 KB |
Output is correct |
46 |
Correct |
89 ms |
384 KB |
Output is correct |
47 |
Correct |
75 ms |
504 KB |
Output is correct |
48 |
Correct |
114 ms |
376 KB |
Output is correct |
49 |
Correct |
99 ms |
508 KB |
Output is correct |
50 |
Correct |
72 ms |
504 KB |
Output is correct |
51 |
Correct |
98 ms |
384 KB |
Output is correct |
52 |
Correct |
97 ms |
384 KB |
Output is correct |
53 |
Correct |
105 ms |
632 KB |
Output is correct |
54 |
Correct |
120 ms |
384 KB |
Output is correct |
55 |
Correct |
122 ms |
376 KB |
Output is correct |
56 |
Correct |
120 ms |
376 KB |
Output is correct |
57 |
Correct |
99 ms |
524 KB |
Output is correct |
58 |
Correct |
95 ms |
504 KB |
Output is correct |
59 |
Correct |
94 ms |
388 KB |
Output is correct |
60 |
Correct |
107 ms |
384 KB |
Output is correct |