#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define ls node << 1
#define rs node << 1 | 1
const int BK = 10, INF = 1.5e9;
int n, m, lim;
int A[5005][205], B[5005][205];
int f[10][205][205], sum[205], p[205][205];
int T[1025][205][205];
void get(int node, int id)
{
int l = (id - 1) * BK + 1, r = min(n, id * BK), now = 0;
for(int i = 1; i <= m; i++)
{
for(int j = i + 1; j <= m; j++)
f[now][i][j] = f[now][i][j - 1] + A[l][j - 1];
for(int j = i - 1; j >= 1; j--)
f[now][i][j] = f[now][i][j + 1] + A[l][j];
}
for(int k = l + 1; k <= r; k++)
{
now ++;
for(int i = 1; i < m; i++) sum[i] = sum[i - 1] + A[k][i];
for(int i = 1; i <= m; i++)
{
int mn = INF;
for(int j = 1; j <= m; j++)
{
mn = min(mn, f[now - 1][i][j] + B[k - 1][j] - sum[j - 1]);
f[now][i][j] = mn + sum[j - 1];
}
mn = INF;
for(int j = m; j >= 1; j--)
{
mn = min(mn, f[now - 1][i][j] + B[k - 1][j] + sum[j - 1]);
f[now][i][j] = min(f[now][i][j], mn - sum[j - 1]);
}
}
}
for(int i = 1; i <= m; i++)
for(int j = 1; j <= m; j++)
T[node][i][j] = f[now][i][j];
}
void pushup(int node, int mid)
{
mid *= BK;
for(int l = m; l >= 1; l--)
for(int r = 1; r <= m; r++)
{
int nl = (r == 1 ? 1 : p[l][r - 1]), nr = (l == m ? m : p[l + 1][r]);
T[node][l][r] = INF;
for(int md = nl; md <= nr; md++)
{
int tp = T[ls][l][md] + B[mid][md] + T[rs][md][r];
if(tp < T[node][l][r]) T[node][l][r] = tp, p[l][r] = md;
}
}
}
void build(int node, int l, int r)
{
if(l == r)
{
get(node, l);
return;
}
int mid = (l + r) >> 1;
build(ls, l, mid);
build(rs, mid + 1, r);
pushup(node, mid);
}
void change(int node, int l, int r, int x)
{
if(l == r)
{
get(node, l);
return;
}
int mid = (l + r) >> 1;
if(x <= mid) change(ls, l, mid, x);
else change(rs, mid + 1, r, x);
pushup(node, mid);
}
void changeH(int P, int Q, int W)
{
P ++, Q ++;
A[P][Q] = W;
change(1, 1, lim, (P - 1) / BK + 1);
}
void changeV(int P, int Q, int W)
{
P ++, Q ++;
B[P][Q] = W;
change(1, 1, lim, (P - 1) / BK + 1);
}
int escape(int V1, int V2)
{
V1 ++, V2 ++;
return T[1][V1][V2];
}
void init(int R, int C, int H[5000][200], int V[5000][200])
{
n = R, m = C;
for(int i = 1; i <= n; i++)
for(int j = 1; j < m; j++)
A[i][j] = H[i - 1][j - 1];
for(int i = 1; i < n; i++)
for(int j = 1; j <= m; j++)
B[i][j] = V[i - 1][j - 1];
lim = (n - 1) / BK + 1;
build(1, 1, lim);
}
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 |
12492 KB |
Output is correct |
2 |
Correct |
7 ms |
12492 KB |
Output is correct |
3 |
Correct |
90 ms |
14132 KB |
Output is correct |
4 |
Correct |
8 ms |
12492 KB |
Output is correct |
5 |
Correct |
7 ms |
12492 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
91 ms |
1576 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
3148 KB |
Output is correct |
2 |
Correct |
65 ms |
3020 KB |
Output is correct |
3 |
Correct |
80 ms |
3148 KB |
Output is correct |
4 |
Correct |
89 ms |
3148 KB |
Output is correct |
5 |
Correct |
81 ms |
3100 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
319 ms |
3116 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
21300 KB |
Output is correct |
2 |
Correct |
13 ms |
21324 KB |
Output is correct |
3 |
Correct |
16 ms |
21328 KB |
Output is correct |
4 |
Correct |
67 ms |
22096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
3128 KB |
Output is correct |
2 |
Correct |
76 ms |
3096 KB |
Output is correct |
3 |
Correct |
92 ms |
3148 KB |
Output is correct |
4 |
Correct |
80 ms |
3148 KB |
Output is correct |
5 |
Correct |
75 ms |
3096 KB |
Output is correct |
6 |
Correct |
12 ms |
21324 KB |
Output is correct |
7 |
Correct |
17 ms |
21320 KB |
Output is correct |
8 |
Correct |
12 ms |
21324 KB |
Output is correct |
9 |
Correct |
56 ms |
22088 KB |
Output is correct |
10 |
Correct |
9 ms |
12604 KB |
Output is correct |
11 |
Correct |
7 ms |
12492 KB |
Output is correct |
12 |
Correct |
101 ms |
14100 KB |
Output is correct |
13 |
Correct |
7 ms |
12492 KB |
Output is correct |
14 |
Correct |
7 ms |
12492 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
2 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
588 KB |
Output is correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Correct |
92 ms |
1688 KB |
Output is correct |
26 |
Correct |
2 ms |
588 KB |
Output is correct |
27 |
Correct |
319 ms |
3148 KB |
Output is correct |
28 |
Correct |
937 ms |
101276 KB |
Output is correct |
29 |
Correct |
943 ms |
83540 KB |
Output is correct |
30 |
Correct |
892 ms |
83504 KB |
Output is correct |
31 |
Correct |
964 ms |
102520 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
3148 KB |
Output is correct |
2 |
Correct |
67 ms |
3108 KB |
Output is correct |
3 |
Correct |
72 ms |
3156 KB |
Output is correct |
4 |
Correct |
73 ms |
3268 KB |
Output is correct |
5 |
Correct |
94 ms |
3104 KB |
Output is correct |
6 |
Correct |
17 ms |
21324 KB |
Output is correct |
7 |
Correct |
17 ms |
21228 KB |
Output is correct |
8 |
Correct |
16 ms |
21324 KB |
Output is correct |
9 |
Correct |
55 ms |
22132 KB |
Output is correct |
10 |
Correct |
7 ms |
12492 KB |
Output is correct |
11 |
Correct |
8 ms |
12588 KB |
Output is correct |
12 |
Correct |
87 ms |
14140 KB |
Output is correct |
13 |
Correct |
9 ms |
12492 KB |
Output is correct |
14 |
Correct |
5 ms |
12492 KB |
Output is correct |
15 |
Correct |
1280 ms |
182216 KB |
Output is correct |
16 |
Correct |
3874 ms |
183844 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
588 KB |
Output is correct |
22 |
Correct |
2 ms |
588 KB |
Output is correct |
23 |
Correct |
2 ms |
588 KB |
Output is correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
87 ms |
1612 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
353 ms |
3152 KB |
Output is correct |
30 |
Correct |
989 ms |
101240 KB |
Output is correct |
31 |
Correct |
3468 ms |
182840 KB |
Output is correct |
32 |
Correct |
3697 ms |
182860 KB |
Output is correct |
33 |
Correct |
1040 ms |
83584 KB |
Output is correct |
34 |
Correct |
3463 ms |
150632 KB |
Output is correct |
35 |
Correct |
1012 ms |
83376 KB |
Output is correct |
36 |
Correct |
3341 ms |
150628 KB |
Output is correct |
37 |
Correct |
976 ms |
102352 KB |
Output is correct |
38 |
Correct |
3216 ms |
183628 KB |
Output is correct |
39 |
Correct |
1 ms |
432 KB |
Output is correct |
40 |
Correct |
3422 ms |
150492 KB |
Output is correct |