#include <iostream>
#include "xylophone.h"
using namespace std;
const int maxN = 6e3 + 226;
int val[maxN], q1[maxN], q2[maxN], a, b, c, minAt, maxAt, ans[maxN];
void solve(int N){
int a, b, c;
for(int i = 1; i < N; i++){
q1[i] = query(i, i + 1);
}
for(int i = 1; i < N - 1; i++){
q2[i] = query(i, i + 2);
}
val[2] = q1[1];
for(int i = 3; i <= N; i++){
a = q1[i - 2], b = q1[i - 1], c = q2[i - 2];
if(a + b == c){
if(val[i - 1] > 0) val[i] = b;
else val[i] = -b;
} else {
if(val[i - 1] > 0) val[i] = -b;
else val[i] = b;
}
}
minAt = maxAt = 1;
for(int i = 1; i <= N; i++){
ans[i] = val[i] + ans[i - 1];
if(ans[minAt] > ans[i]) minAt = i;
if(ans[maxAt] < ans[i]) maxAt = i;
}
if(minAt < maxAt){
for(int i = 1; i <= N; i++) answer(i, ans[i] - ans[minAt] + 1);
return;
}
minAt = maxAt = 1;
for(int i = 1; i <= N; i++){
ans[i] = -val[i] + ans[i - 1];
if(ans[minAt] > ans[i]) minAt = i;
if(ans[maxAt] < ans[i]) maxAt = i;
}
for(int i = 1; i <= N; i++) answer(i, ans[i] - ans[minAt] + 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
380 KB |
Output is correct |
7 |
Correct |
6 ms |
380 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
248 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
6 ms |
248 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
380 KB |
Output is correct |
7 |
Correct |
6 ms |
380 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
248 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
6 ms |
248 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
248 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
14 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
248 KB |
Output is correct |
19 |
Correct |
14 ms |
316 KB |
Output is correct |
20 |
Correct |
23 ms |
248 KB |
Output is correct |
21 |
Correct |
20 ms |
376 KB |
Output is correct |
22 |
Correct |
20 ms |
248 KB |
Output is correct |
23 |
Correct |
22 ms |
380 KB |
Output is correct |
24 |
Correct |
27 ms |
376 KB |
Output is correct |
25 |
Correct |
27 ms |
248 KB |
Output is correct |
26 |
Correct |
22 ms |
248 KB |
Output is correct |
27 |
Correct |
20 ms |
248 KB |
Output is correct |
28 |
Correct |
23 ms |
248 KB |
Output is correct |
29 |
Correct |
24 ms |
248 KB |
Output is correct |
30 |
Correct |
20 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
7 ms |
248 KB |
Output is correct |
6 |
Correct |
6 ms |
380 KB |
Output is correct |
7 |
Correct |
6 ms |
380 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
248 KB |
Output is correct |
10 |
Correct |
6 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
248 KB |
Output is correct |
12 |
Correct |
6 ms |
248 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
7 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
248 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
14 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
248 KB |
Output is correct |
19 |
Correct |
14 ms |
316 KB |
Output is correct |
20 |
Correct |
23 ms |
248 KB |
Output is correct |
21 |
Correct |
20 ms |
376 KB |
Output is correct |
22 |
Correct |
20 ms |
248 KB |
Output is correct |
23 |
Correct |
22 ms |
380 KB |
Output is correct |
24 |
Correct |
27 ms |
376 KB |
Output is correct |
25 |
Correct |
27 ms |
248 KB |
Output is correct |
26 |
Correct |
22 ms |
248 KB |
Output is correct |
27 |
Correct |
20 ms |
248 KB |
Output is correct |
28 |
Correct |
23 ms |
248 KB |
Output is correct |
29 |
Correct |
24 ms |
248 KB |
Output is correct |
30 |
Correct |
20 ms |
248 KB |
Output is correct |
31 |
Correct |
40 ms |
404 KB |
Output is correct |
32 |
Correct |
65 ms |
332 KB |
Output is correct |
33 |
Correct |
86 ms |
504 KB |
Output is correct |
34 |
Correct |
93 ms |
504 KB |
Output is correct |
35 |
Correct |
103 ms |
504 KB |
Output is correct |
36 |
Correct |
85 ms |
504 KB |
Output is correct |
37 |
Correct |
92 ms |
376 KB |
Output is correct |
38 |
Correct |
89 ms |
436 KB |
Output is correct |
39 |
Correct |
94 ms |
376 KB |
Output is correct |
40 |
Correct |
92 ms |
428 KB |
Output is correct |
41 |
Correct |
71 ms |
320 KB |
Output is correct |
42 |
Correct |
93 ms |
376 KB |
Output is correct |
43 |
Correct |
78 ms |
504 KB |
Output is correct |
44 |
Correct |
74 ms |
320 KB |
Output is correct |
45 |
Correct |
86 ms |
340 KB |
Output is correct |
46 |
Correct |
87 ms |
456 KB |
Output is correct |
47 |
Correct |
80 ms |
376 KB |
Output is correct |
48 |
Correct |
102 ms |
508 KB |
Output is correct |
49 |
Correct |
90 ms |
504 KB |
Output is correct |
50 |
Correct |
102 ms |
504 KB |
Output is correct |
51 |
Correct |
90 ms |
376 KB |
Output is correct |
52 |
Correct |
92 ms |
376 KB |
Output is correct |
53 |
Correct |
92 ms |
504 KB |
Output is correct |
54 |
Correct |
97 ms |
376 KB |
Output is correct |
55 |
Correct |
91 ms |
376 KB |
Output is correct |
56 |
Correct |
92 ms |
504 KB |
Output is correct |
57 |
Correct |
91 ms |
504 KB |
Output is correct |
58 |
Correct |
90 ms |
376 KB |
Output is correct |
59 |
Correct |
100 ms |
376 KB |
Output is correct |
60 |
Correct |
101 ms |
376 KB |
Output is correct |