#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
static int a[5005];
static int d[5005][5005];
void solve(int n) {
int dis = query(1, 2);
for(int i=3; i<=n; i++) {
d[i - 2][i] = query(i - 2, i);
d[i - 1][i] = query(i - 1, i);
}
for(int i=1; i<=n; i++) {
a[1] = i;
for(int k=-1; k<=1; k+=2) {
a[2] = a[1] + k*dis;
for(int j=3; j<=n; j++) {
int cal = max(a[j - 1], a[j - 2]) - min(a[j - 1], a[j - 2]);
if(d[j - 2][j] == cal) {
if(a[j - 1] > a[j - 2]) a[j] = a[j - 1] - d[j - 1][j];
else a[j] = a[j - 1] + d[j - 1][j];
}
else {
if(a[j - 1] + d[j - 1][j] - min(a[j - 2], a[j - 1]) == d[j - 2][j]) a[j] = a[j - 1] + d[j - 1][j];
if(max(a[j - 2], a[j - 1]) - (a[j - 1] - d[j - 1][j]) == d[j - 2][j]) a[j] = a[j - 1] - d[j - 1][j];
}
}
int mi = 1e9, mx = -1e9;
long long sum = 0;
for(int j=1; j<=n; j++) {
mi = min(mi, a[j]);
mx = max(mx, a[j]);
sum += a[j];
}
if(mi == 1 && mx == n && sum == 1LL*n*(n + 1)/2) {
int p1, pn;
for(int j=1; j<=n; j++) {
if(a[j] == 1) p1 = j;
if(a[j] == n) pn = j;
}
if(p1 < pn) {
for(int j=1; j<=n; j++) answer(j, a[j]);
return;
}
}
}
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:43:17: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
43 | if(p1 < pn) {
| ^~
xylophone.cpp:43:17: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2504 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2504 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
6484 KB |
Output is correct |
17 |
Correct |
9 ms |
10584 KB |
Output is correct |
18 |
Correct |
8 ms |
16728 KB |
Output is correct |
19 |
Correct |
15 ms |
21224 KB |
Output is correct |
20 |
Correct |
18 ms |
21080 KB |
Output is correct |
21 |
Correct |
16 ms |
20988 KB |
Output is correct |
22 |
Correct |
15 ms |
20824 KB |
Output is correct |
23 |
Correct |
13 ms |
21080 KB |
Output is correct |
24 |
Correct |
10 ms |
20824 KB |
Output is correct |
25 |
Correct |
8 ms |
20824 KB |
Output is correct |
26 |
Correct |
16 ms |
20964 KB |
Output is correct |
27 |
Correct |
14 ms |
21080 KB |
Output is correct |
28 |
Correct |
12 ms |
20968 KB |
Output is correct |
29 |
Correct |
13 ms |
20824 KB |
Output is correct |
30 |
Correct |
12 ms |
20824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2504 KB |
Output is correct |
10 |
Correct |
2 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2516 KB |
Output is correct |
12 |
Correct |
2 ms |
2392 KB |
Output is correct |
13 |
Correct |
2 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
6484 KB |
Output is correct |
17 |
Correct |
9 ms |
10584 KB |
Output is correct |
18 |
Correct |
8 ms |
16728 KB |
Output is correct |
19 |
Correct |
15 ms |
21224 KB |
Output is correct |
20 |
Correct |
18 ms |
21080 KB |
Output is correct |
21 |
Correct |
16 ms |
20988 KB |
Output is correct |
22 |
Correct |
15 ms |
20824 KB |
Output is correct |
23 |
Correct |
13 ms |
21080 KB |
Output is correct |
24 |
Correct |
10 ms |
20824 KB |
Output is correct |
25 |
Correct |
8 ms |
20824 KB |
Output is correct |
26 |
Correct |
16 ms |
20964 KB |
Output is correct |
27 |
Correct |
14 ms |
21080 KB |
Output is correct |
28 |
Correct |
12 ms |
20968 KB |
Output is correct |
29 |
Correct |
13 ms |
20824 KB |
Output is correct |
30 |
Correct |
12 ms |
20824 KB |
Output is correct |
31 |
Correct |
44 ms |
43344 KB |
Output is correct |
32 |
Correct |
94 ms |
62004 KB |
Output is correct |
33 |
Correct |
107 ms |
86556 KB |
Output is correct |
34 |
Correct |
170 ms |
96984 KB |
Output is correct |
35 |
Correct |
173 ms |
97532 KB |
Output is correct |
36 |
Correct |
60 ms |
97624 KB |
Output is correct |
37 |
Correct |
162 ms |
97120 KB |
Output is correct |
38 |
Correct |
59 ms |
97124 KB |
Output is correct |
39 |
Correct |
85 ms |
97040 KB |
Output is correct |
40 |
Correct |
128 ms |
97284 KB |
Output is correct |
41 |
Correct |
181 ms |
97148 KB |
Output is correct |
42 |
Correct |
50 ms |
97364 KB |
Output is correct |
43 |
Correct |
161 ms |
97288 KB |
Output is correct |
44 |
Correct |
75 ms |
97572 KB |
Output is correct |
45 |
Correct |
129 ms |
97392 KB |
Output is correct |
46 |
Correct |
198 ms |
97456 KB |
Output is correct |
47 |
Correct |
215 ms |
97384 KB |
Output is correct |
48 |
Correct |
62 ms |
97580 KB |
Output is correct |
49 |
Correct |
220 ms |
97404 KB |
Output is correct |
50 |
Correct |
210 ms |
97104 KB |
Output is correct |
51 |
Correct |
111 ms |
97384 KB |
Output is correct |
52 |
Correct |
86 ms |
97084 KB |
Output is correct |
53 |
Correct |
211 ms |
97104 KB |
Output is correct |
54 |
Correct |
170 ms |
97256 KB |
Output is correct |
55 |
Correct |
180 ms |
97192 KB |
Output is correct |
56 |
Correct |
206 ms |
97400 KB |
Output is correct |
57 |
Correct |
224 ms |
97104 KB |
Output is correct |
58 |
Correct |
232 ms |
97104 KB |
Output is correct |
59 |
Correct |
162 ms |
97468 KB |
Output is correct |
60 |
Correct |
144 ms |
97360 KB |
Output is correct |