#include "bits/stdc++.h"
using namespace std;
#include "xylophone.h"
int a[5001], b1[5001], b2[5001];
bool sol(int n, int j) {
a[j] = 1;
int b[n + 1];
for(int i = j - 1; i >= 1; i--) {
int x = b1[i];
b[i] = x;
if(i == j - 1) {
a[i] = x + 1;
continue;
}
int y = b2[i];
if(a[i + 1] < a[i + 2]) {
if(a[i + 1] + x < a[i + 2]) {
if(y == b[i + 1])
a[i] = a[i + 1] + x;
else
a[i] = a[i + 1] - x;
}
else {
if(y == a[i + 2] - (a[i + 1] - x))
a[i] = a[i + 1] - x;
else
a[i] = a[i + 1] + x;
}
}
else {
if(a[i + 1] - x > a[i + 2]) {
if(y == b[i + 1])
a[i] = a[i + 1] - x;
else
a[i] = a[i + 1] + x;
}
else {
if(y == (a[i + 1] + x) - a[i + 2])
a[i] = a[i + 1] + x;
else
a[i] = a[i + 1] - x;
}
}
}
for(int i = j + 1; i <= n; i++) {
int x = b1[i - 1];
b[i] = x;
if(i == j + 1) {
a[i] = x + 1;
continue;
}
int y = b2[i - 2];
if(a[i - 1] < a[i - 2]) {
if(a[i - 1] + x < a[i - 2]) {
if(y == b[i - 1])
a[i] = a[i - 1] + x;
else
a[i] = a[i - 1] - x;
}
else {
if(y == a[i - 2] - (a[i - 1] - x))
a[i] = a[i - 1] - x;
else
a[i] = a[i - 1] + x;
}
}
else {
if(a[i - 1] - x > a[i - 2]) {
if(b[i - 1] == y)
a[i] = a[i - 1] - x;
else
a[i] = a[i - 1] + x;
}
else {
if(y == (a[i - 1] + x) - a[i - 2])
a[i] = a[i - 1] + x;
else
a[i] = a[i - 1] - x;
}
}
}
vector<int> ve;
for(int i = 1; i <= n; i++)
ve.push_back(a[i]);
sort(ve.begin(), ve.end());
for(int i = 1; i <= n; i++) {
if(ve[i - 1] != i)
return 0;
}
return 1;
}
void solve(int n) {
for(int i = 1; i <= n; i++) {
a[i] = 0;
if(i + 1 <= n)
b1[i] = query(i, i + 1);
if(i + 2 <= n)
b2[i] = query(i, i + 2);
}
for(int i = 1; i <= n; i++) {
if(sol(n, i))
break;
}
for(int i = 1; i <= n; i++)
answer(i, a[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
4 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
256 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 |
4 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
4 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
256 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 |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
12 ms |
312 KB |
Output is correct |
18 |
Correct |
16 ms |
316 KB |
Output is correct |
19 |
Correct |
25 ms |
316 KB |
Output is correct |
20 |
Correct |
32 ms |
300 KB |
Output is correct |
21 |
Correct |
40 ms |
312 KB |
Output is correct |
22 |
Correct |
32 ms |
428 KB |
Output is correct |
23 |
Correct |
20 ms |
300 KB |
Output is correct |
24 |
Correct |
49 ms |
300 KB |
Output is correct |
25 |
Correct |
21 ms |
304 KB |
Output is correct |
26 |
Correct |
32 ms |
312 KB |
Output is correct |
27 |
Correct |
42 ms |
316 KB |
Output is correct |
28 |
Correct |
28 ms |
308 KB |
Output is correct |
29 |
Correct |
33 ms |
304 KB |
Output is correct |
30 |
Correct |
28 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
2 ms |
208 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
4 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
256 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 |
4 ms |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
12 ms |
312 KB |
Output is correct |
18 |
Correct |
16 ms |
316 KB |
Output is correct |
19 |
Correct |
25 ms |
316 KB |
Output is correct |
20 |
Correct |
32 ms |
300 KB |
Output is correct |
21 |
Correct |
40 ms |
312 KB |
Output is correct |
22 |
Correct |
32 ms |
428 KB |
Output is correct |
23 |
Correct |
20 ms |
300 KB |
Output is correct |
24 |
Correct |
49 ms |
300 KB |
Output is correct |
25 |
Correct |
21 ms |
304 KB |
Output is correct |
26 |
Correct |
32 ms |
312 KB |
Output is correct |
27 |
Correct |
42 ms |
316 KB |
Output is correct |
28 |
Correct |
28 ms |
308 KB |
Output is correct |
29 |
Correct |
33 ms |
304 KB |
Output is correct |
30 |
Correct |
28 ms |
304 KB |
Output is correct |
31 |
Correct |
113 ms |
348 KB |
Output is correct |
32 |
Correct |
286 ms |
376 KB |
Output is correct |
33 |
Correct |
568 ms |
408 KB |
Output is correct |
34 |
Correct |
907 ms |
444 KB |
Output is correct |
35 |
Correct |
922 ms |
412 KB |
Output is correct |
36 |
Correct |
78 ms |
468 KB |
Output is correct |
37 |
Correct |
840 ms |
412 KB |
Output is correct |
38 |
Correct |
99 ms |
344 KB |
Output is correct |
39 |
Correct |
624 ms |
304 KB |
Output is correct |
40 |
Correct |
286 ms |
408 KB |
Output is correct |
41 |
Correct |
624 ms |
412 KB |
Output is correct |
42 |
Correct |
54 ms |
432 KB |
Output is correct |
43 |
Correct |
829 ms |
412 KB |
Output is correct |
44 |
Correct |
77 ms |
340 KB |
Output is correct |
45 |
Correct |
131 ms |
416 KB |
Output is correct |
46 |
Correct |
257 ms |
408 KB |
Output is correct |
47 |
Correct |
93 ms |
340 KB |
Output is correct |
48 |
Correct |
229 ms |
412 KB |
Output is correct |
49 |
Correct |
775 ms |
408 KB |
Output is correct |
50 |
Correct |
782 ms |
412 KB |
Output is correct |
51 |
Correct |
87 ms |
336 KB |
Output is correct |
52 |
Correct |
1189 ms |
416 KB |
Output is correct |
53 |
Correct |
638 ms |
424 KB |
Output is correct |
54 |
Correct |
286 ms |
416 KB |
Output is correct |
55 |
Correct |
217 ms |
428 KB |
Output is correct |
56 |
Correct |
539 ms |
432 KB |
Output is correct |
57 |
Correct |
366 ms |
412 KB |
Output is correct |
58 |
Correct |
1439 ms |
436 KB |
Output is correct |
59 |
Correct |
477 ms |
412 KB |
Output is correct |
60 |
Correct |
751 ms |
412 KB |
Output is correct |