// M
#include<bits/stdc++.h>
#include "wombats.h"
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#define lc (id << 1)
#define rc (lc ^ 1)
#define md ((l + r) >> 1)
using namespace std;
const int N = 5005, M = 202, MXS = 512, SQ = 20, INF = 1e9 + 9;
int n, m, H[N][M], V[N][M];
int dp[MXS][M][M];
int TMp[M][M], Opt[M][M];
inline void BuildBlock(int l, int r)
{
memset(TMp, 63, sizeof(TMp));
for (int st = 0; st < m; st ++)
{
TMp[st][st] = 0;
for (int i = l; i < r; i ++)
{
for (int j = 1; j < m; j ++)
TMp[st][j] = min(TMp[st][j], TMp[st][j - 1] + H[i][j - 1]);
for (int j = m - 2; j >= 0; j --)
TMp[st][j] = min(TMp[st][j], TMp[st][j + 1] + H[i][j]);
for (int j = 0; j < m; j ++)
TMp[st][j] += V[i][j];
}
}
}
inline void Merge(int id, int le, int ri)
{
for (int sm = - m; sm < m; sm ++)
for (int st = 0; st < m; st ++)
{
int fn = sm + st;
if (fn < 0 || fn >= m)
continue;
int l = fn ? Opt[st][fn - 1] : 0;
int r = (st + 1 < m) ? Opt[st + 1][fn] : (m - 1);
int opt = -1, Mn = INF;
for (int i = l; i <= r; i ++)
if (Mn > dp[le][st][i] + dp[ri][i][fn])
Mn = dp[le][st][i] + dp[ri][i][fn], opt = i;
Opt[st][fn] = opt;
dp[id][st][fn] = Mn;
}
}
void BuildSegTree(int id = 1, int l = 0, int r = n)
{
if (r - l <= SQ)
{
BuildBlock(l, r);
memcpy(dp[id], TMp, sizeof(TMp));
return ;
}
BuildSegTree(lc, l, md);
BuildSegTree(rc, md, r);
Merge(id, lc, rc);
}
void init(int _n, int _m, int _H[5000][200], int _V[5000][200])
{
n = _n; m = _m;
for (int i = 0; i < n; i ++)
for (int j = 0; j + 1 < m; j ++)
H[i][j] = _H[i][j];
for (int i = 0; i + 1 < n; i ++)
for (int j = 0; j < m; j ++)
V[i][j] = _V[i][j];
BuildSegTree();
}
void Update(int i, int id = 1, int l = 0, int r = n)
{
if (r - l <= SQ)
{
BuildBlock(l, r);
memcpy(dp[id], TMp, sizeof(TMp));
return ;
}
if (i < md)
Update(i, lc, l, md);
else
Update(i, rc, md, r);
Merge(id, lc, rc);
}
void changeH(int r, int c, int w)
{
H[r][c] = w;
Update(r);
}
void changeV(int r, int c, int w)
{
V[r][c] = w;
Update(r);
}
int escape(int st, int fn)
{
return dp[1][st][fn];
}
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 |
45 ms |
50296 KB |
Output is correct |
2 |
Correct |
48 ms |
50328 KB |
Output is correct |
3 |
Correct |
153 ms |
51960 KB |
Output is correct |
4 |
Correct |
53 ms |
50296 KB |
Output is correct |
5 |
Correct |
47 ms |
50296 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
672 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
103 ms |
1784 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
2816 KB |
Output is correct |
2 |
Correct |
79 ms |
2816 KB |
Output is correct |
3 |
Correct |
91 ms |
2816 KB |
Output is correct |
4 |
Correct |
142 ms |
2816 KB |
Output is correct |
5 |
Correct |
95 ms |
2816 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
640 KB |
Output is correct |
9 |
Correct |
375 ms |
2816 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
58448 KB |
Output is correct |
2 |
Correct |
50 ms |
58360 KB |
Output is correct |
3 |
Correct |
55 ms |
58364 KB |
Output is correct |
4 |
Correct |
114 ms |
59256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
2816 KB |
Output is correct |
2 |
Correct |
82 ms |
2816 KB |
Output is correct |
3 |
Correct |
94 ms |
2816 KB |
Output is correct |
4 |
Correct |
93 ms |
2816 KB |
Output is correct |
5 |
Correct |
91 ms |
2816 KB |
Output is correct |
6 |
Correct |
54 ms |
58360 KB |
Output is correct |
7 |
Correct |
53 ms |
58360 KB |
Output is correct |
8 |
Correct |
55 ms |
58360 KB |
Output is correct |
9 |
Correct |
94 ms |
59256 KB |
Output is correct |
10 |
Correct |
45 ms |
50304 KB |
Output is correct |
11 |
Correct |
56 ms |
50300 KB |
Output is correct |
12 |
Correct |
132 ms |
51960 KB |
Output is correct |
13 |
Correct |
46 ms |
50296 KB |
Output is correct |
14 |
Correct |
45 ms |
50304 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
2 ms |
768 KB |
Output is correct |
19 |
Correct |
2 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
768 KB |
Output is correct |
24 |
Correct |
2 ms |
768 KB |
Output is correct |
25 |
Correct |
138 ms |
1784 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
392 ms |
2936 KB |
Output is correct |
28 |
Correct |
1317 ms |
78616 KB |
Output is correct |
29 |
Correct |
1232 ms |
76152 KB |
Output is correct |
30 |
Correct |
1297 ms |
76024 KB |
Output is correct |
31 |
Correct |
1262 ms |
79900 KB |
Output is correct |
32 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
2840 KB |
Output is correct |
2 |
Correct |
78 ms |
2816 KB |
Output is correct |
3 |
Correct |
92 ms |
2816 KB |
Output is correct |
4 |
Correct |
90 ms |
2816 KB |
Output is correct |
5 |
Correct |
90 ms |
2816 KB |
Output is correct |
6 |
Correct |
54 ms |
58360 KB |
Output is correct |
7 |
Correct |
53 ms |
58360 KB |
Output is correct |
8 |
Correct |
60 ms |
58360 KB |
Output is correct |
9 |
Correct |
97 ms |
59232 KB |
Output is correct |
10 |
Correct |
48 ms |
50296 KB |
Output is correct |
11 |
Correct |
47 ms |
50296 KB |
Output is correct |
12 |
Correct |
126 ms |
51960 KB |
Output is correct |
13 |
Correct |
50 ms |
50296 KB |
Output is correct |
14 |
Correct |
47 ms |
50428 KB |
Output is correct |
15 |
Correct |
1110 ms |
98012 KB |
Output is correct |
16 |
Correct |
4590 ms |
99848 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
768 KB |
Output is correct |
21 |
Correct |
1 ms |
768 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
768 KB |
Output is correct |
24 |
Correct |
1 ms |
768 KB |
Output is correct |
25 |
Correct |
1 ms |
768 KB |
Output is correct |
26 |
Correct |
1 ms |
768 KB |
Output is correct |
27 |
Correct |
83 ms |
1784 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
382 ms |
2816 KB |
Output is correct |
30 |
Correct |
1169 ms |
78880 KB |
Output is correct |
31 |
Correct |
4221 ms |
98868 KB |
Output is correct |
32 |
Correct |
4346 ms |
98940 KB |
Output is correct |
33 |
Correct |
1187 ms |
76116 KB |
Output is correct |
34 |
Correct |
4207 ms |
95928 KB |
Output is correct |
35 |
Correct |
1220 ms |
75768 KB |
Output is correct |
36 |
Correct |
4340 ms |
96128 KB |
Output is correct |
37 |
Correct |
1330 ms |
79736 KB |
Output is correct |
38 |
Correct |
4392 ms |
99620 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
4478 ms |
95940 KB |
Output is correct |