#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int m[5009][5009], A[5009], D[5009];
int get(int s, int t) {
if(s == t) return 0;
if(m[s][t] == -1) m[s][t] = query(s, t);
return m[s][t];
}
void solve(int N) {
memset(m, -1, sizeof(m));
A[1] = 0; A[2] = get(1, 2);
bool inc = 1;
for(int i=3; i<=N; i++) {
if(inc) {
if(get(i-2, i-1) == get(i-2, i)) A[i] = A[i-1] - get(i-1, i), inc = 0;
else {
if(A[i-2] + get(i-2, i) == A[i-1] + get(i-1, i)) A[i] = A[i-1] + get(i-1, i);
else A[i] = A[i-1] - get(i-1, i), inc = 0;
}
}
else {
if(get(i-2, i-1) == get(i-2, i)) A[i] = A[i-1] + get(i-1, i), inc = 1;
else {
if(A[i-2] - get(i-2, i) == A[i-1] - get(i-1, i)) A[i] = A[i-1] - get(i-1, i);
else A[i] = A[i-1] + get(i-1, i), inc = 1;
}
}
}
int mn = 1, mx = 1;
for(int i=1; i<=N; i++) {
if(A[mn] > A[i]) mn = i;
if(A[mx] < A[i]) mx = i;
D[i] = A[i] - A[i-1];
}
if(mn > mx) {
for(int i=2, s=0; i<=N; i++) s += -D[i], A[i] = s;
swap(mn, mx);
}
for(int i=1; i<=N; i++) answer(i, A[i] - A[mn] + 1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
98552 KB |
Output is correct |
2 |
Correct |
67 ms |
98424 KB |
Output is correct |
3 |
Correct |
68 ms |
98428 KB |
Output is correct |
4 |
Correct |
67 ms |
98424 KB |
Output is correct |
5 |
Correct |
69 ms |
98424 KB |
Output is correct |
6 |
Correct |
69 ms |
98416 KB |
Output is correct |
7 |
Correct |
71 ms |
98424 KB |
Output is correct |
8 |
Correct |
71 ms |
98464 KB |
Output is correct |
9 |
Correct |
70 ms |
98552 KB |
Output is correct |
10 |
Correct |
69 ms |
98472 KB |
Output is correct |
11 |
Correct |
80 ms |
98552 KB |
Output is correct |
12 |
Correct |
82 ms |
98424 KB |
Output is correct |
13 |
Correct |
80 ms |
98428 KB |
Output is correct |
14 |
Correct |
82 ms |
98424 KB |
Output is correct |
15 |
Correct |
85 ms |
98424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
98552 KB |
Output is correct |
2 |
Correct |
67 ms |
98424 KB |
Output is correct |
3 |
Correct |
68 ms |
98428 KB |
Output is correct |
4 |
Correct |
67 ms |
98424 KB |
Output is correct |
5 |
Correct |
69 ms |
98424 KB |
Output is correct |
6 |
Correct |
69 ms |
98416 KB |
Output is correct |
7 |
Correct |
71 ms |
98424 KB |
Output is correct |
8 |
Correct |
71 ms |
98464 KB |
Output is correct |
9 |
Correct |
70 ms |
98552 KB |
Output is correct |
10 |
Correct |
69 ms |
98472 KB |
Output is correct |
11 |
Correct |
80 ms |
98552 KB |
Output is correct |
12 |
Correct |
82 ms |
98424 KB |
Output is correct |
13 |
Correct |
80 ms |
98428 KB |
Output is correct |
14 |
Correct |
82 ms |
98424 KB |
Output is correct |
15 |
Correct |
85 ms |
98424 KB |
Output is correct |
16 |
Correct |
82 ms |
98524 KB |
Output is correct |
17 |
Correct |
87 ms |
98596 KB |
Output is correct |
18 |
Correct |
85 ms |
98516 KB |
Output is correct |
19 |
Correct |
85 ms |
98516 KB |
Output is correct |
20 |
Correct |
96 ms |
98680 KB |
Output is correct |
21 |
Correct |
85 ms |
98520 KB |
Output is correct |
22 |
Correct |
97 ms |
98656 KB |
Output is correct |
23 |
Correct |
96 ms |
98524 KB |
Output is correct |
24 |
Correct |
97 ms |
98476 KB |
Output is correct |
25 |
Correct |
97 ms |
98552 KB |
Output is correct |
26 |
Correct |
98 ms |
98424 KB |
Output is correct |
27 |
Correct |
99 ms |
98520 KB |
Output is correct |
28 |
Correct |
79 ms |
98560 KB |
Output is correct |
29 |
Correct |
99 ms |
98556 KB |
Output is correct |
30 |
Correct |
98 ms |
98424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
98552 KB |
Output is correct |
2 |
Correct |
67 ms |
98424 KB |
Output is correct |
3 |
Correct |
68 ms |
98428 KB |
Output is correct |
4 |
Correct |
67 ms |
98424 KB |
Output is correct |
5 |
Correct |
69 ms |
98424 KB |
Output is correct |
6 |
Correct |
69 ms |
98416 KB |
Output is correct |
7 |
Correct |
71 ms |
98424 KB |
Output is correct |
8 |
Correct |
71 ms |
98464 KB |
Output is correct |
9 |
Correct |
70 ms |
98552 KB |
Output is correct |
10 |
Correct |
69 ms |
98472 KB |
Output is correct |
11 |
Correct |
80 ms |
98552 KB |
Output is correct |
12 |
Correct |
82 ms |
98424 KB |
Output is correct |
13 |
Correct |
80 ms |
98428 KB |
Output is correct |
14 |
Correct |
82 ms |
98424 KB |
Output is correct |
15 |
Correct |
85 ms |
98424 KB |
Output is correct |
16 |
Correct |
82 ms |
98524 KB |
Output is correct |
17 |
Correct |
87 ms |
98596 KB |
Output is correct |
18 |
Correct |
85 ms |
98516 KB |
Output is correct |
19 |
Correct |
85 ms |
98516 KB |
Output is correct |
20 |
Correct |
96 ms |
98680 KB |
Output is correct |
21 |
Correct |
85 ms |
98520 KB |
Output is correct |
22 |
Correct |
97 ms |
98656 KB |
Output is correct |
23 |
Correct |
96 ms |
98524 KB |
Output is correct |
24 |
Correct |
97 ms |
98476 KB |
Output is correct |
25 |
Correct |
97 ms |
98552 KB |
Output is correct |
26 |
Correct |
98 ms |
98424 KB |
Output is correct |
27 |
Correct |
99 ms |
98520 KB |
Output is correct |
28 |
Correct |
79 ms |
98560 KB |
Output is correct |
29 |
Correct |
99 ms |
98556 KB |
Output is correct |
30 |
Correct |
98 ms |
98424 KB |
Output is correct |
31 |
Correct |
114 ms |
98540 KB |
Output is correct |
32 |
Correct |
129 ms |
98628 KB |
Output is correct |
33 |
Correct |
160 ms |
98556 KB |
Output is correct |
34 |
Correct |
160 ms |
98440 KB |
Output is correct |
35 |
Correct |
112 ms |
98548 KB |
Output is correct |
36 |
Correct |
112 ms |
98584 KB |
Output is correct |
37 |
Correct |
171 ms |
98652 KB |
Output is correct |
38 |
Correct |
170 ms |
98524 KB |
Output is correct |
39 |
Correct |
163 ms |
98604 KB |
Output is correct |
40 |
Correct |
167 ms |
98628 KB |
Output is correct |
41 |
Correct |
170 ms |
98652 KB |
Output is correct |
42 |
Correct |
173 ms |
98556 KB |
Output is correct |
43 |
Correct |
167 ms |
98600 KB |
Output is correct |
44 |
Correct |
159 ms |
98552 KB |
Output is correct |
45 |
Correct |
170 ms |
98640 KB |
Output is correct |
46 |
Correct |
165 ms |
98524 KB |
Output is correct |
47 |
Correct |
179 ms |
98552 KB |
Output is correct |
48 |
Correct |
167 ms |
98556 KB |
Output is correct |
49 |
Correct |
113 ms |
98632 KB |
Output is correct |
50 |
Correct |
107 ms |
98544 KB |
Output is correct |
51 |
Correct |
166 ms |
98552 KB |
Output is correct |
52 |
Correct |
111 ms |
98640 KB |
Output is correct |
53 |
Correct |
164 ms |
98556 KB |
Output is correct |
54 |
Correct |
164 ms |
98524 KB |
Output is correct |
55 |
Correct |
168 ms |
98476 KB |
Output is correct |
56 |
Correct |
164 ms |
98608 KB |
Output is correct |
57 |
Correct |
117 ms |
98524 KB |
Output is correct |
58 |
Correct |
159 ms |
98472 KB |
Output is correct |
59 |
Correct |
148 ms |
98552 KB |
Output is correct |
60 |
Correct |
169 ms |
98552 KB |
Output is correct |