#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 5007;
int p[N];
void solve(int n){
if(n == 1){
answer(1, 1);
return;
}
p[1] = 0;
p[2] = query(1, 2);
for(int i = 3; i <= n; i++){
int ret1 = query(i - 1, i), ret2 = query(i - 2, i);
if(p[i - 1] > p[i - 2]){
if(ret2 == ret1 + abs(p[i - 1] - p[i - 2])) p[i] = p[i - 1] + ret1;
else p[i] = p[i - 1] - ret1;
}
else{
if(ret2 == ret1 + abs(p[i - 1] - p[i - 2])) p[i] = p[i - 1] - ret1;
else p[i] = p[i - 1] + ret1;
}
}
int val = 1e9;
for(int i = 1; i <= n; i++){
if(p[i] < val) val = p[i];
}
int pos1, posn;
for(int i = 1; i <= n; i++){
p[i] += (1 - val);
if(p[i] == 1) pos1 = i;
if(p[i] == n) posn = i;
}
if(pos1 > posn){
for(int i = 1; i <= n; i++){
p[i] = n - p[i] + 1;
}
}
for(int i = 1; i <= n; i++) answer(i, p[i]);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:42:2: warning: 'posn' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(pos1 > posn){
^~
xylophone.cpp:42:2: warning: 'pos1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
324 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
324 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
256 KB |
Output is correct |
19 |
Correct |
18 ms |
256 KB |
Output is correct |
20 |
Correct |
9 ms |
328 KB |
Output is correct |
21 |
Correct |
17 ms |
256 KB |
Output is correct |
22 |
Correct |
19 ms |
384 KB |
Output is correct |
23 |
Correct |
17 ms |
256 KB |
Output is correct |
24 |
Correct |
16 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
256 KB |
Output is correct |
26 |
Correct |
20 ms |
384 KB |
Output is correct |
27 |
Correct |
16 ms |
256 KB |
Output is correct |
28 |
Correct |
23 ms |
384 KB |
Output is correct |
29 |
Correct |
16 ms |
256 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
324 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
256 KB |
Output is correct |
19 |
Correct |
18 ms |
256 KB |
Output is correct |
20 |
Correct |
9 ms |
328 KB |
Output is correct |
21 |
Correct |
17 ms |
256 KB |
Output is correct |
22 |
Correct |
19 ms |
384 KB |
Output is correct |
23 |
Correct |
17 ms |
256 KB |
Output is correct |
24 |
Correct |
16 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
256 KB |
Output is correct |
26 |
Correct |
20 ms |
384 KB |
Output is correct |
27 |
Correct |
16 ms |
256 KB |
Output is correct |
28 |
Correct |
23 ms |
384 KB |
Output is correct |
29 |
Correct |
16 ms |
256 KB |
Output is correct |
30 |
Correct |
14 ms |
384 KB |
Output is correct |
31 |
Correct |
41 ms |
256 KB |
Output is correct |
32 |
Correct |
26 ms |
404 KB |
Output is correct |
33 |
Correct |
57 ms |
504 KB |
Output is correct |
34 |
Correct |
77 ms |
384 KB |
Output is correct |
35 |
Correct |
72 ms |
328 KB |
Output is correct |
36 |
Correct |
82 ms |
384 KB |
Output is correct |
37 |
Correct |
79 ms |
444 KB |
Output is correct |
38 |
Correct |
69 ms |
256 KB |
Output is correct |
39 |
Correct |
65 ms |
428 KB |
Output is correct |
40 |
Correct |
52 ms |
456 KB |
Output is correct |
41 |
Correct |
77 ms |
384 KB |
Output is correct |
42 |
Correct |
78 ms |
384 KB |
Output is correct |
43 |
Correct |
82 ms |
384 KB |
Output is correct |
44 |
Correct |
71 ms |
256 KB |
Output is correct |
45 |
Correct |
50 ms |
412 KB |
Output is correct |
46 |
Correct |
38 ms |
328 KB |
Output is correct |
47 |
Correct |
70 ms |
384 KB |
Output is correct |
48 |
Correct |
72 ms |
256 KB |
Output is correct |
49 |
Correct |
36 ms |
324 KB |
Output is correct |
50 |
Correct |
86 ms |
512 KB |
Output is correct |
51 |
Correct |
69 ms |
256 KB |
Output is correct |
52 |
Correct |
73 ms |
460 KB |
Output is correct |
53 |
Correct |
72 ms |
376 KB |
Output is correct |
54 |
Correct |
65 ms |
384 KB |
Output is correct |
55 |
Correct |
47 ms |
444 KB |
Output is correct |
56 |
Correct |
52 ms |
384 KB |
Output is correct |
57 |
Correct |
86 ms |
452 KB |
Output is correct |
58 |
Correct |
76 ms |
456 KB |
Output is correct |
59 |
Correct |
74 ms |
384 KB |
Output is correct |
60 |
Correct |
87 ms |
444 KB |
Output is correct |