#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int n) {
vector<int> a(n + 1);
vector<int> b(n + 1);
for (int i = 1; i <= n - 1; i++) {
a[i] = query(i, i + 1);
}
for (int i = 1; i <= n - 2; i++) {
b[i] = query(i, i + 2);
}
vector<bool> f(n + 1);
vector<int> res(n + 1);
for (int i = 1; i <= n; i++) {
res[1] = i;
for (int j = -1; j <= 1; j += 2) {
fill(f.begin(), f.end(), false);
f[res[1]] = true;
res[2] = res[1] + a[1] * j;
if (res[2] < 1 || res[2] > n || f[res[2]]) {
continue;
}
f[res[2]] = true;
bool ok = true;
for (int k = 3; k <= n; k++) {
bool g = false;
for (int l = -1; l <= 1; l += 2) {
res[k] = res[k - 1] + a[k - 1] * l;
if (res[k] < 1 || res[k] > n || f[res[k]]) {
continue;
}
if (max({res[k - 2], res[k - 1], res[k]}) - min({res[k - 2], res[k - 1], res[k]}) != b[k - 2]) {
continue;
}
f[res[k]] = true;
g = true;
break;
}
if (!g) {
ok = false;
break;
}
}
if (ok) {
int px = -1;
int py = -1;
for (int k = 1; k <= n; k++) {
if (res[k] == 1) {
px = k;
}
if (res[k] == n) {
py = k;
}
}
if (px < py) {
for (int k = 1; k <= n; k++) {
answer(k, res[k]);
}
}
}
}
}
}
# |
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 |
2 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 |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
3 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 |
2 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 |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
3 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 |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
15 ms |
208 KB |
Output is correct |
19 |
Correct |
15 ms |
208 KB |
Output is correct |
20 |
Correct |
19 ms |
300 KB |
Output is correct |
21 |
Correct |
19 ms |
292 KB |
Output is correct |
22 |
Correct |
16 ms |
284 KB |
Output is correct |
23 |
Correct |
24 ms |
208 KB |
Output is correct |
24 |
Correct |
26 ms |
208 KB |
Output is correct |
25 |
Correct |
16 ms |
292 KB |
Output is correct |
26 |
Correct |
14 ms |
288 KB |
Output is correct |
27 |
Correct |
15 ms |
208 KB |
Output is correct |
28 |
Correct |
17 ms |
208 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 |
2 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 |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
3 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 |
8 ms |
208 KB |
Output is correct |
18 |
Correct |
15 ms |
208 KB |
Output is correct |
19 |
Correct |
15 ms |
208 KB |
Output is correct |
20 |
Correct |
19 ms |
300 KB |
Output is correct |
21 |
Correct |
19 ms |
292 KB |
Output is correct |
22 |
Correct |
16 ms |
284 KB |
Output is correct |
23 |
Correct |
24 ms |
208 KB |
Output is correct |
24 |
Correct |
26 ms |
208 KB |
Output is correct |
25 |
Correct |
16 ms |
292 KB |
Output is correct |
26 |
Correct |
14 ms |
288 KB |
Output is correct |
27 |
Correct |
15 ms |
208 KB |
Output is correct |
28 |
Correct |
17 ms |
208 KB |
Output is correct |
29 |
Correct |
20 ms |
208 KB |
Output is correct |
30 |
Correct |
19 ms |
208 KB |
Output is correct |
31 |
Correct |
38 ms |
292 KB |
Output is correct |
32 |
Correct |
48 ms |
304 KB |
Output is correct |
33 |
Correct |
79 ms |
312 KB |
Output is correct |
34 |
Correct |
88 ms |
336 KB |
Output is correct |
35 |
Correct |
95 ms |
328 KB |
Output is correct |
36 |
Correct |
197 ms |
336 KB |
Output is correct |
37 |
Correct |
229 ms |
336 KB |
Output is correct |
38 |
Correct |
84 ms |
336 KB |
Output is correct |
39 |
Correct |
98 ms |
336 KB |
Output is correct |
40 |
Correct |
79 ms |
328 KB |
Output is correct |
41 |
Correct |
80 ms |
336 KB |
Output is correct |
42 |
Correct |
228 ms |
348 KB |
Output is correct |
43 |
Correct |
237 ms |
336 KB |
Output is correct |
44 |
Correct |
78 ms |
336 KB |
Output is correct |
45 |
Correct |
73 ms |
408 KB |
Output is correct |
46 |
Correct |
95 ms |
336 KB |
Output is correct |
47 |
Correct |
75 ms |
336 KB |
Output is correct |
48 |
Correct |
90 ms |
336 KB |
Output is correct |
49 |
Correct |
110 ms |
336 KB |
Output is correct |
50 |
Correct |
53 ms |
336 KB |
Output is correct |
51 |
Correct |
81 ms |
316 KB |
Output is correct |
52 |
Correct |
83 ms |
336 KB |
Output is correct |
53 |
Correct |
92 ms |
340 KB |
Output is correct |
54 |
Correct |
84 ms |
328 KB |
Output is correct |
55 |
Correct |
96 ms |
316 KB |
Output is correct |
56 |
Correct |
91 ms |
328 KB |
Output is correct |
57 |
Correct |
90 ms |
336 KB |
Output is correct |
58 |
Correct |
90 ms |
336 KB |
Output is correct |
59 |
Correct |
47 ms |
336 KB |
Output is correct |
60 |
Correct |
97 ms |
336 KB |
Output is correct |