#include "wombats.h"
#include <bits/stdc++.h>
#define INF (0x3f3f3f3f)
using namespace std;
int A[5001][201], B[5001][201], C[5001][201];
int H, W, Q;
int fdi[201][201];
void f(int du[][201], int dd[][201], int dp[][201], int m) {
for(int i = 1, r, ri; i <= W; i++) {
r = INF;
for(int j = 1, t; j <= W; j++) {
t = du[i][j] + B[m][j] + dd[j][i];
if(t < r) { r = t; ri = j; }
}
dp[i][i] = r; fdi[i][i] = ri;
}
for(int q = 1; q < W; q++) {
for(int s = 1, e = q+1, r, ri, rie; e <= W; s++, e++) {
r = INF; rie = fdi[s+1][e];
for(int j = fdi[s][e-1], t; j <= rie; j++) {
t = du[s][j] + B[m][j] + dd[j][e];
if(t < r) { r = t; ri = j; }
}
dp[s][e] = r; fdi[s][e] = ri;
}
for(int s = q+1, e = 1, r, ri, rie; s <= W; s++, e++) {
r = INF; rie = fdi[s][e+1];
for(int j = fdi[s-1][e], t; j <= rie; j++) {
t = du[s][j] + B[m][j] + dd[j][e];
if(t < r) { r = t; ri = j; }
}
dp[s][e] = r; fdi[s][e] = ri;
}
}
}
int rdp[3][201][201];
void run(int dp[][201], int x) {
for(int i = 1; i <= W; i++) {
dp[i][i] = 0;
for(int j = i+1; j <= W; j++)
dp[i][j] = dp[j][i] = C[x][j]-C[x][i];
}
}
void run(int dp[][201], int s, int e) {
run(rdp[0], s);
for(int i = s+1; i <= e; i++) {
run(rdp[1], i);
f(rdp[0], rdp[1], rdp[2], i-1);
memcpy(rdp[0], rdp[2], 201*201*4);
}
memcpy(dp, rdp[0], 201*201*4);
}
struct NOD {
int dp[201][201];
NOD *pl = NULL, *pr = NULL;
void cal(int s, int e) {
if(e-s < 20) {
run(dp, s, e);
return;
}
int m = (s+e) >> 1;
pl = new NOD(); pr = new NOD();
pl -> cal(s, m); pr -> cal(m+1, e);
f(pl->dp, pr->dp, dp, m);
}
void upd(int s, int e, int x) {
if(e-s < 20) {
run(dp, s, e);
return;
}
int m = (s+e) >> 1;
if(x <= m) pl -> upd(s, m, x);
else pr -> upd(m+1, e, x);
f(pl->dp, pr->dp, dp, m);
}
} nod;
void init(int H, int W, int A[5000][200], int B[5000][200]) {
::H = H; ::W = W;
for(int i = 1; i <= H; i++) {
for(int j = 1; j < W; j++) {
int c = A[i-1][j-1];
::A[i][j] = c;
::C[i][j+1] = ::C[i][j] + c;
}
}
for(int i = 1; i < H; i++)
for(int j = 1; j <= W; j++)
::B[i][j] = B[i-1][j-1];
nod.cal(1, H);
}
void changeH(int a, int b, int c) {
a++; b++;
A[a][b] = c;
for(int i = 1; i < W; i++)
C[a][i+1] = C[a][i] + A[a][i];
nod.upd(1, H, a);
}
void changeV(int a, int b, int c) {
a++; b++;
B[a][b] = c;
nod.upd(1, H, a);
}
int escape(int a, int b) {
return nod.dp[a+1][b+1];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
wombats.cpp: In function 'void f(int (*)[201], int (*)[201], int (*)[201], int)':
wombats.cpp:35:28: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
35 | dp[s][e] = r; fdi[s][e] = ri;
| ~~~~~~~~~~^~~~
wombats.cpp:27:28: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | dp[s][e] = r; fdi[s][e] = ri;
| ~~~~~~~~~~^~~~
wombats.cpp:18:27: warning: 'ri' may be used uninitialized in this function [-Wmaybe-uninitialized]
18 | dp[i][i] = r; fdi[i][i] = ri;
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
90004 KB |
Output is correct |
2 |
Correct |
134 ms |
90132 KB |
Output is correct |
3 |
Correct |
178 ms |
92988 KB |
Output is correct |
4 |
Correct |
119 ms |
90188 KB |
Output is correct |
5 |
Correct |
114 ms |
90008 KB |
Output is correct |
6 |
Correct |
1 ms |
572 KB |
Output is correct |
7 |
Correct |
1 ms |
572 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
708 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
708 KB |
Output is correct |
11 |
Correct |
64 ms |
3100 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
3480 KB |
Output is correct |
2 |
Correct |
111 ms |
3540 KB |
Output is correct |
3 |
Correct |
155 ms |
3540 KB |
Output is correct |
4 |
Correct |
154 ms |
3512 KB |
Output is correct |
5 |
Correct |
155 ms |
3540 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
493 ms |
3544 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
101940 KB |
Output is correct |
2 |
Correct |
132 ms |
101812 KB |
Output is correct |
3 |
Correct |
140 ms |
101836 KB |
Output is correct |
4 |
Correct |
153 ms |
103304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
3536 KB |
Output is correct |
2 |
Correct |
119 ms |
3540 KB |
Output is correct |
3 |
Correct |
156 ms |
3544 KB |
Output is correct |
4 |
Correct |
153 ms |
3544 KB |
Output is correct |
5 |
Correct |
154 ms |
3540 KB |
Output is correct |
6 |
Correct |
128 ms |
101952 KB |
Output is correct |
7 |
Correct |
124 ms |
101916 KB |
Output is correct |
8 |
Correct |
125 ms |
101896 KB |
Output is correct |
9 |
Correct |
158 ms |
103432 KB |
Output is correct |
10 |
Correct |
118 ms |
90108 KB |
Output is correct |
11 |
Correct |
117 ms |
90128 KB |
Output is correct |
12 |
Correct |
179 ms |
92912 KB |
Output is correct |
13 |
Correct |
127 ms |
90116 KB |
Output is correct |
14 |
Correct |
115 ms |
90092 KB |
Output is correct |
15 |
Correct |
1 ms |
572 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
572 KB |
Output is correct |
18 |
Correct |
1 ms |
708 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
764 KB |
Output is correct |
23 |
Correct |
1 ms |
704 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
67 ms |
3140 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
530 ms |
3528 KB |
Output is correct |
28 |
Correct |
1385 ms |
106552 KB |
Output is correct |
29 |
Correct |
1541 ms |
102456 KB |
Output is correct |
30 |
Correct |
2025 ms |
102596 KB |
Output is correct |
31 |
Correct |
1565 ms |
107960 KB |
Output is correct |
32 |
Correct |
1 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
3548 KB |
Output is correct |
2 |
Correct |
118 ms |
3520 KB |
Output is correct |
3 |
Correct |
176 ms |
3544 KB |
Output is correct |
4 |
Correct |
172 ms |
3464 KB |
Output is correct |
5 |
Correct |
178 ms |
3464 KB |
Output is correct |
6 |
Correct |
186 ms |
101940 KB |
Output is correct |
7 |
Correct |
128 ms |
101920 KB |
Output is correct |
8 |
Correct |
136 ms |
102060 KB |
Output is correct |
9 |
Correct |
166 ms |
103332 KB |
Output is correct |
10 |
Correct |
120 ms |
90100 KB |
Output is correct |
11 |
Correct |
122 ms |
90100 KB |
Output is correct |
12 |
Correct |
188 ms |
92868 KB |
Output is correct |
13 |
Correct |
148 ms |
90132 KB |
Output is correct |
14 |
Correct |
158 ms |
90132 KB |
Output is correct |
15 |
Correct |
1666 ms |
112212 KB |
Output is correct |
16 |
Correct |
6561 ms |
113352 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
576 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
724 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
772 KB |
Output is correct |
23 |
Correct |
2 ms |
704 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
64 ms |
3132 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
506 ms |
3540 KB |
Output is correct |
30 |
Correct |
1346 ms |
106420 KB |
Output is correct |
31 |
Correct |
4877 ms |
110892 KB |
Output is correct |
32 |
Correct |
4924 ms |
111128 KB |
Output is correct |
33 |
Correct |
1543 ms |
102712 KB |
Output is correct |
34 |
Correct |
5755 ms |
107000 KB |
Output is correct |
35 |
Correct |
1553 ms |
102544 KB |
Output is correct |
36 |
Correct |
5543 ms |
106840 KB |
Output is correct |
37 |
Correct |
1487 ms |
107980 KB |
Output is correct |
38 |
Correct |
5322 ms |
111752 KB |
Output is correct |
39 |
Correct |
1 ms |
596 KB |
Output is correct |
40 |
Correct |
5577 ms |
107468 KB |
Output is correct |