#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXR = 5003;
const int MAXC = 203;
const int INF = 1e9;
constexpr int BLOK = 10;
int H[MAXR][MAXC]={},V[MAXR][MAXC]={};
int dp[(MAXR+BLOK-1)/BLOK*4][MAXC][MAXC];
int opt[MAXC][MAXC];
int cur[MAXC][MAXC];
int C,R,sz;
void merge(int x){
if (x*2+1>=sz){
if (x-sz/2<(R+BLOK-1)/BLOK){
for (int i = 0; i < C; i++){
for (int j = 0; j < C; j++){
dp[x][i][j]=INF;
}
dp[x][i][i]=0;
}
for (int _ = (x-sz/2)*BLOK; _ < min(R,(x-sz/2+1)*BLOK); _++){
for (int i = 0; i < C; i++){
int somma = 0;
for (int j = i; j < C; j++){
cur[i][j]=somma+V[_][j];
somma+=H[_][j];
}
somma = 0;
for (int j = i-1; j >= 0; j--){
somma+=H[_][j];
cur[i][j]=somma+V[_][j];
}
}
int edp[MAXC][MAXC];
for (int i = C-1; i >= 0; i--){
for (int j = 0; j < C; j++){
int lbound = 0;
int rbound = C-1;
if (j) lbound=opt[i][j-1];
if (i+1<C) rbound=opt[i+1][j];
edp[i][j]=dp[x][i][lbound]+cur[lbound][j];
opt[i][j]=lbound;
for (int k = lbound; k <= rbound; k++){
if (dp[x][i][k]+cur[k][j]<edp[i][j]){
edp[i][j]=dp[x][i][k]+cur[k][j];
opt[i][j]=k;
}
}
}
}
for (int i = 0; i < C; i++){
for (int j = 0; j < C; j++){
dp[x][i][j]=edp[i][j];
}
}
}
}
else {
for (int i = 0; i < C; i++){
for (int j = 0; j < C; j++){
if (i==j) dp[x][i][j]=0;
else dp[x][i][j]=INF;
}
}
}
}
else {
for (int i = C-1; i >= 0; i--){
for (int j = 0; j < C; j++){
int lbound = 0;
int rbound = C-1;
if (j) lbound=opt[i][j-1];
if (i+1<C) rbound=opt[i+1][j];
opt[i][j]=lbound;
dp[x][i][j]=dp[x*2+1][i][lbound]+dp[x*2+2][lbound][j];
for (int k = lbound; k <= rbound; k++){
if (dp[x*2+1][i][k]+dp[x*2+2][k][j]<dp[x][i][j]){
dp[x][i][j]=dp[x*2+1][i][k]+dp[x*2+2][k][j];
opt[i][j]=k;
}
}
}
}
}
}
void init(int RR, int CC, int HH[5000][200], int VV[5000][200]) {
C=CC,R=RR;
sz=(1LL<<((int)(ceil(log2((R+BLOK-1)/BLOK)+1))))-1;
for (int i = 0; i < R; i++){
for (int j = 0; j < C; j++){
if (j+1<C) H[i][j]=HH[i][j];
if (i+1<R) V[i][j]=VV[i][j];
}
}
for (int i = sz-1; i >= 0; i--){
merge(i);
}
}
void changeH(int P, int Q, int W) {
H[P][Q]=W;
P/=BLOK;
P+=sz/2;
merge(P);
while (P){
P=(P-1)/2;
merge(P);
}
}
void changeV(int P, int Q, int W) {
V[P][Q]=W;
P/=BLOK;
P+=sz/2;
merge(P);
while (P){
P=(P-1)/2;
merge(P);
}
}
int escape(int V1, int V2) {
return dp[0][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]
15 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12920 KB |
Output is correct |
2 |
Correct |
8 ms |
12892 KB |
Output is correct |
3 |
Correct |
44 ms |
14356 KB |
Output is correct |
4 |
Correct |
8 ms |
12888 KB |
Output is correct |
5 |
Correct |
8 ms |
12892 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
38 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
3676 KB |
Output is correct |
2 |
Correct |
69 ms |
3420 KB |
Output is correct |
3 |
Correct |
92 ms |
3676 KB |
Output is correct |
4 |
Correct |
85 ms |
3676 KB |
Output is correct |
5 |
Correct |
88 ms |
3420 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
301 ms |
3676 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21596 KB |
Output is correct |
2 |
Correct |
11 ms |
21388 KB |
Output is correct |
3 |
Correct |
13 ms |
21608 KB |
Output is correct |
4 |
Correct |
31 ms |
22176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
3676 KB |
Output is correct |
2 |
Correct |
68 ms |
3420 KB |
Output is correct |
3 |
Correct |
92 ms |
3920 KB |
Output is correct |
4 |
Correct |
85 ms |
3672 KB |
Output is correct |
5 |
Correct |
84 ms |
3640 KB |
Output is correct |
6 |
Correct |
11 ms |
21596 KB |
Output is correct |
7 |
Correct |
11 ms |
21596 KB |
Output is correct |
8 |
Correct |
12 ms |
21620 KB |
Output is correct |
9 |
Correct |
30 ms |
22152 KB |
Output is correct |
10 |
Correct |
8 ms |
12892 KB |
Output is correct |
11 |
Correct |
8 ms |
12908 KB |
Output is correct |
12 |
Correct |
45 ms |
14416 KB |
Output is correct |
13 |
Correct |
8 ms |
12892 KB |
Output is correct |
14 |
Correct |
10 ms |
12888 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
38 ms |
1628 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
316 ms |
3688 KB |
Output is correct |
28 |
Correct |
768 ms |
102044 KB |
Output is correct |
29 |
Correct |
806 ms |
99176 KB |
Output is correct |
30 |
Correct |
838 ms |
99152 KB |
Output is correct |
31 |
Correct |
782 ms |
102828 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
3664 KB |
Output is correct |
2 |
Correct |
68 ms |
3420 KB |
Output is correct |
3 |
Correct |
110 ms |
3676 KB |
Output is correct |
4 |
Correct |
85 ms |
3672 KB |
Output is correct |
5 |
Correct |
83 ms |
3416 KB |
Output is correct |
6 |
Correct |
11 ms |
21596 KB |
Output is correct |
7 |
Correct |
11 ms |
21596 KB |
Output is correct |
8 |
Correct |
12 ms |
21460 KB |
Output is correct |
9 |
Correct |
30 ms |
22364 KB |
Output is correct |
10 |
Correct |
8 ms |
12892 KB |
Output is correct |
11 |
Correct |
7 ms |
12892 KB |
Output is correct |
12 |
Correct |
43 ms |
14396 KB |
Output is correct |
13 |
Correct |
8 ms |
12888 KB |
Output is correct |
14 |
Correct |
8 ms |
12892 KB |
Output is correct |
15 |
Correct |
1113 ms |
181652 KB |
Output is correct |
16 |
Correct |
3254 ms |
183124 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
680 KB |
Output is correct |
26 |
Correct |
0 ms |
604 KB |
Output is correct |
27 |
Correct |
39 ms |
1692 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
308 ms |
3676 KB |
Output is correct |
30 |
Correct |
740 ms |
101968 KB |
Output is correct |
31 |
Correct |
2830 ms |
182356 KB |
Output is correct |
32 |
Correct |
2819 ms |
182184 KB |
Output is correct |
33 |
Correct |
849 ms |
99164 KB |
Output is correct |
34 |
Correct |
3237 ms |
179460 KB |
Output is correct |
35 |
Correct |
966 ms |
98920 KB |
Output is correct |
36 |
Correct |
3248 ms |
179540 KB |
Output is correct |
37 |
Correct |
853 ms |
102948 KB |
Output is correct |
38 |
Correct |
2929 ms |
182872 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
3340 ms |
179320 KB |
Output is correct |