#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5000];
int dva[5005];
int tri[5005];
int res[5005];
int nadji(int a, int b, int c){
return max(abs(a-c), max(abs(a-b), abs(b-c)));
}
void solve(int N) {
if(N == 1){
answer(1, 1);
return;
}
for(int i=1; i<N; i++){
dva[i] = query(i, i+1);
}
for(int i=1; i<N-1; i++){
tri[i] = query(i, i+2);
}
res[2] = dva[1];
for(int i=3; i<=N; i++){
if(nadji(res[i-2], res[i-1], dva[i-1] + res[i-1]) == tri[i-2]) res[i] = dva[i-1] + res[i-1];
else res[i] = res[i-1] - dva[i-1];
}
int mn = 0;
for(int i=1; i<=N; i++){
mn = min(mn, res[i]);
}
for(int i=1; i<=N; i++){
res[i] += 1-mn;
}
int b1 = 0, bn = 0;
for(int i=1; i<=N; i++){
if(res[i] == 1) b1 = i;
else if(res[i] == N) bn = i;
}
if(b1 > bn){
for(int i=1; i<=N; i++) res[i] = N-res[i]+1;
}
for(int i=1; i<=N; i++){
answer(i, res[i]);
}
}
Compilation message
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5000];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
436 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
436 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
7 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
376 KB |
Output is correct |
19 |
Correct |
18 ms |
384 KB |
Output is correct |
20 |
Correct |
24 ms |
376 KB |
Output is correct |
21 |
Correct |
18 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
27 ms |
384 KB |
Output is correct |
24 |
Correct |
17 ms |
376 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
20 ms |
384 KB |
Output is correct |
28 |
Correct |
16 ms |
504 KB |
Output is correct |
29 |
Correct |
25 ms |
380 KB |
Output is correct |
30 |
Correct |
17 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
436 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
7 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
376 KB |
Output is correct |
19 |
Correct |
18 ms |
384 KB |
Output is correct |
20 |
Correct |
24 ms |
376 KB |
Output is correct |
21 |
Correct |
18 ms |
384 KB |
Output is correct |
22 |
Correct |
17 ms |
384 KB |
Output is correct |
23 |
Correct |
27 ms |
384 KB |
Output is correct |
24 |
Correct |
17 ms |
376 KB |
Output is correct |
25 |
Correct |
23 ms |
384 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
20 ms |
384 KB |
Output is correct |
28 |
Correct |
16 ms |
504 KB |
Output is correct |
29 |
Correct |
25 ms |
380 KB |
Output is correct |
30 |
Correct |
17 ms |
384 KB |
Output is correct |
31 |
Correct |
33 ms |
504 KB |
Output is correct |
32 |
Correct |
50 ms |
508 KB |
Output is correct |
33 |
Correct |
75 ms |
376 KB |
Output is correct |
34 |
Correct |
78 ms |
376 KB |
Output is correct |
35 |
Correct |
48 ms |
504 KB |
Output is correct |
36 |
Correct |
131 ms |
384 KB |
Output is correct |
37 |
Correct |
82 ms |
376 KB |
Output is correct |
38 |
Correct |
92 ms |
404 KB |
Output is correct |
39 |
Correct |
86 ms |
504 KB |
Output is correct |
40 |
Correct |
126 ms |
384 KB |
Output is correct |
41 |
Correct |
91 ms |
388 KB |
Output is correct |
42 |
Correct |
84 ms |
376 KB |
Output is correct |
43 |
Correct |
90 ms |
504 KB |
Output is correct |
44 |
Correct |
115 ms |
376 KB |
Output is correct |
45 |
Correct |
129 ms |
376 KB |
Output is correct |
46 |
Correct |
83 ms |
384 KB |
Output is correct |
47 |
Correct |
84 ms |
376 KB |
Output is correct |
48 |
Correct |
86 ms |
376 KB |
Output is correct |
49 |
Correct |
83 ms |
380 KB |
Output is correct |
50 |
Correct |
129 ms |
376 KB |
Output is correct |
51 |
Correct |
116 ms |
504 KB |
Output is correct |
52 |
Correct |
85 ms |
512 KB |
Output is correct |
53 |
Correct |
122 ms |
376 KB |
Output is correct |
54 |
Correct |
86 ms |
504 KB |
Output is correct |
55 |
Correct |
83 ms |
384 KB |
Output is correct |
56 |
Correct |
86 ms |
376 KB |
Output is correct |
57 |
Correct |
50 ms |
376 KB |
Output is correct |
58 |
Correct |
82 ms |
376 KB |
Output is correct |
59 |
Correct |
85 ms |
388 KB |
Output is correct |
60 |
Correct |
83 ms |
384 KB |
Output is correct |