#include "wombats.h"
int r, c;
const int inf = 1e8;
short h[5000][200];
short v[5000][200];
int iabs(int x) {
return x < 0 ? -x : x;
}
int imin(int x, int y) {
return x < y ? x : y;
}
int tp[200][200];
struct node {
int to[200][200];
void add(const node &l, const node &r, int m) {
for (int i = 0; i < c; ++i) {
to[i][i] = inf;
for (int j = 0; j < c; ++j) {
int x = l.to[i][j] + r.to[j][i] + v[m][j];
if (x < to[i][i]) {
tp[i][i] = j;
to[i][i] = x;
}
}
}
for (int i = 1 - c; i < c; ++i) {
for (int j = 0; j < c; ++j) {
if (j + i < 0 || c <= j + i) continue;
to[j][j + i] = inf;
int s = j + i > 0 ? tp[j][j + i - 1] : 0;
int e = j + 1 < c ? tp[j + 1][j + i] : c - 1;
for (int k = s; k <= e; ++k) {
int x = l.to[j][k] + r.to[k][j + i] + v[m][k];
if (x < to[j][j + i]) {
tp[j][j + i] = k;
to[j][j + i] = x;
}
}
}
}
}
void fill(int x) {
int sum[200] = {};
for (int i = 1; i < c; ++i) {
sum[i] = sum[i - 1] + h[x][i - 1];
}
for (int i = 0; i < c; ++i) {
for (int j = 0; j < c; ++j) {
to[i][j] = iabs(sum[i] - sum[j]);
}
}
}
void init(int s, int e) {
node t1, t2;
fill(s);
for (int i = s + 1; i <= e; ++i) {
t1 = *this;
t2.fill(i);
add(t1, t2, i - 1);
}
}
} seg[1 << 10];
void initSeg(int i, int s, int e) {
if (s == e || (1 << 10) <= (i << 1 | 1)) {
seg[i].init(s, e);
return;
}
int m = (s + e) / 2;
initSeg(i << 1, s, m);
initSeg(i << 1 | 1, m + 1, e);
seg[i].add(seg[i << 1], seg[i << 1 | 1], m);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
if (j + 1 < c) h[i][j] = H[i][j];
if (i + 1 < r) v[i][j] = V[i][j];
}
}
initSeg(1, 0, r - 1);
}
void update(int i, int s, int e, int x) {
if (s == e || (1 << 10) <= (i << 1 | 1)) {
seg[i].init(s, e);
return;
}
int m = (s + e) / 2;
if (x <= m) update(i << 1, s, m, x);
else update(i << 1 | 1, m + 1, e, x);
seg[i].add(seg[i << 1], seg[i << 1 | 1], m);
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
update(1, 0, r - 1, P);
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
update(1, 0, r - 1, P);
}
int escape(int V1, int V2) {
return seg[1].to[V1][V2];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
int res;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
10868 KB |
Output is correct |
2 |
Correct |
139 ms |
10868 KB |
Output is correct |
3 |
Correct |
218 ms |
12436 KB |
Output is correct |
4 |
Correct |
127 ms |
12436 KB |
Output is correct |
5 |
Correct |
136 ms |
12436 KB |
Output is correct |
6 |
Correct |
3 ms |
12436 KB |
Output is correct |
7 |
Correct |
2 ms |
12436 KB |
Output is correct |
8 |
Correct |
2 ms |
12436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12436 KB |
Output is correct |
2 |
Correct |
2 ms |
12436 KB |
Output is correct |
3 |
Correct |
2 ms |
12436 KB |
Output is correct |
4 |
Correct |
4 ms |
12436 KB |
Output is correct |
5 |
Correct |
3 ms |
12436 KB |
Output is correct |
6 |
Correct |
3 ms |
12436 KB |
Output is correct |
7 |
Correct |
3 ms |
12436 KB |
Output is correct |
8 |
Correct |
3 ms |
12436 KB |
Output is correct |
9 |
Correct |
3 ms |
12436 KB |
Output is correct |
10 |
Correct |
3 ms |
12436 KB |
Output is correct |
11 |
Correct |
137 ms |
12436 KB |
Output is correct |
12 |
Correct |
3 ms |
12436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
17200 KB |
Output is correct |
2 |
Correct |
121 ms |
17200 KB |
Output is correct |
3 |
Correct |
160 ms |
17328 KB |
Output is correct |
4 |
Correct |
172 ms |
17372 KB |
Output is correct |
5 |
Correct |
140 ms |
17372 KB |
Output is correct |
6 |
Correct |
2 ms |
17372 KB |
Output is correct |
7 |
Correct |
2 ms |
17372 KB |
Output is correct |
8 |
Correct |
2 ms |
17372 KB |
Output is correct |
9 |
Correct |
547 ms |
17424 KB |
Output is correct |
10 |
Correct |
2 ms |
17424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
17712 KB |
Output is correct |
2 |
Correct |
130 ms |
17712 KB |
Output is correct |
3 |
Correct |
129 ms |
17712 KB |
Output is correct |
4 |
Correct |
167 ms |
18444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
18444 KB |
Output is correct |
2 |
Correct |
121 ms |
18444 KB |
Output is correct |
3 |
Correct |
155 ms |
18444 KB |
Output is correct |
4 |
Correct |
147 ms |
18444 KB |
Output is correct |
5 |
Correct |
144 ms |
18444 KB |
Output is correct |
6 |
Correct |
147 ms |
18444 KB |
Output is correct |
7 |
Correct |
169 ms |
18444 KB |
Output is correct |
8 |
Correct |
138 ms |
18444 KB |
Output is correct |
9 |
Correct |
190 ms |
18480 KB |
Output is correct |
10 |
Correct |
129 ms |
18480 KB |
Output is correct |
11 |
Correct |
132 ms |
18480 KB |
Output is correct |
12 |
Correct |
220 ms |
18480 KB |
Output is correct |
13 |
Correct |
138 ms |
18480 KB |
Output is correct |
14 |
Correct |
124 ms |
18480 KB |
Output is correct |
15 |
Correct |
2 ms |
18480 KB |
Output is correct |
16 |
Correct |
3 ms |
18480 KB |
Output is correct |
17 |
Correct |
2 ms |
18480 KB |
Output is correct |
18 |
Correct |
3 ms |
18480 KB |
Output is correct |
19 |
Correct |
3 ms |
18480 KB |
Output is correct |
20 |
Correct |
3 ms |
18480 KB |
Output is correct |
21 |
Correct |
2 ms |
18480 KB |
Output is correct |
22 |
Correct |
3 ms |
18480 KB |
Output is correct |
23 |
Correct |
3 ms |
18480 KB |
Output is correct |
24 |
Correct |
3 ms |
18480 KB |
Output is correct |
25 |
Correct |
80 ms |
18480 KB |
Output is correct |
26 |
Correct |
3 ms |
18480 KB |
Output is correct |
27 |
Correct |
479 ms |
18480 KB |
Output is correct |
28 |
Correct |
2286 ms |
96948 KB |
Output is correct |
29 |
Correct |
2304 ms |
96948 KB |
Output is correct |
30 |
Correct |
2584 ms |
96948 KB |
Output is correct |
31 |
Correct |
2627 ms |
98088 KB |
Output is correct |
32 |
Correct |
2 ms |
98088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
98088 KB |
Output is correct |
2 |
Correct |
116 ms |
98088 KB |
Output is correct |
3 |
Correct |
150 ms |
98088 KB |
Output is correct |
4 |
Correct |
161 ms |
98088 KB |
Output is correct |
5 |
Correct |
194 ms |
98088 KB |
Output is correct |
6 |
Correct |
132 ms |
98088 KB |
Output is correct |
7 |
Correct |
134 ms |
98088 KB |
Output is correct |
8 |
Correct |
150 ms |
98088 KB |
Output is correct |
9 |
Correct |
165 ms |
98088 KB |
Output is correct |
10 |
Correct |
120 ms |
98088 KB |
Output is correct |
11 |
Correct |
119 ms |
98088 KB |
Output is correct |
12 |
Correct |
190 ms |
98088 KB |
Output is correct |
13 |
Correct |
136 ms |
98088 KB |
Output is correct |
14 |
Correct |
120 ms |
98088 KB |
Output is correct |
15 |
Correct |
3574 ms |
173204 KB |
Output is correct |
16 |
Correct |
11152 ms |
184212 KB |
Output is correct |
17 |
Correct |
2 ms |
184212 KB |
Output is correct |
18 |
Correct |
2 ms |
184212 KB |
Output is correct |
19 |
Correct |
2 ms |
184212 KB |
Output is correct |
20 |
Correct |
3 ms |
184212 KB |
Output is correct |
21 |
Correct |
3 ms |
184212 KB |
Output is correct |
22 |
Correct |
3 ms |
184212 KB |
Output is correct |
23 |
Correct |
3 ms |
184212 KB |
Output is correct |
24 |
Correct |
3 ms |
184212 KB |
Output is correct |
25 |
Correct |
3 ms |
184212 KB |
Output is correct |
26 |
Correct |
3 ms |
184212 KB |
Output is correct |
27 |
Correct |
92 ms |
184212 KB |
Output is correct |
28 |
Correct |
4 ms |
184212 KB |
Output is correct |
29 |
Correct |
549 ms |
184212 KB |
Output is correct |
30 |
Correct |
2254 ms |
184212 KB |
Output is correct |
31 |
Correct |
9784 ms |
196364 KB |
Output is correct |
32 |
Correct |
9160 ms |
204032 KB |
Output is correct |
33 |
Correct |
2408 ms |
204032 KB |
Output is correct |
34 |
Correct |
9152 ms |
212640 KB |
Output is correct |
35 |
Correct |
2516 ms |
212640 KB |
Output is correct |
36 |
Correct |
9274 ms |
223020 KB |
Output is correct |
37 |
Correct |
2238 ms |
223020 KB |
Output is correct |
38 |
Correct |
9316 ms |
237948 KB |
Output is correct |
39 |
Correct |
2 ms |
237948 KB |
Output is correct |
40 |
Correct |
9081 ms |
242548 KB |
Output is correct |