#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
const int mxR = 5000;
const int mxC = 200;
const int bs = 20;
const int mxN = mxR / 20;
int h[mxR][mxC], v[mxR][mxC];
int H[mxN << 2], L[mxN << 2];
int opt[mxC + 1];
int nds[mxN << 2][mxC][mxC];
void build(int x, int lo, int hi) {
L[x] = lo; H[x] = hi;
if (lo == hi) {
return ;
}
int mid = (lo + hi) >> 1;
build(x << 1, lo, mid);
build(x << 1 | 1, mid + 1, hi);
}
void upd(int x, int l, int r) {
if (L[x] == H[x]) {
for (int i = 0; i < mxC; i++) {
for (int j = 0; j < mxC; j++) {
nds[x][i][j] = inf;
}
}
for (int j = 0; j < mxC; j++) {
nds[x][j][j] = 0;
for (int i = L[x] * bs; i < (L[x] + 1) * bs; i++) {
for (int k = 1; k < mxC; k++) {
nds[x][j][k] = min(nds[x][j][k], nds[x][j][k - 1] + h[i][k - 1]);
}
for (int k = mxC - 1; k; k--) {
nds[x][j][k - 1] = min(nds[x][j][k - 1], nds[x][j][k] + h[i][k - 1]);
}
for (int k = 0; k < mxC; k++) {
nds[x][j][k] += v[i][k];
}
}
}
return ;
}
if (l <= H[x << 1]) {
upd(x << 1, l, r);
}
if (H[x << 1] < r) {
upd(x << 1 | 1, l, r);
}
memset(opt, 0, mxC * 4);
for (int i = 0; i < mxC; i++) {
for (int j = mxC - 1; ~j; j--) {
array<int, 2> mn = {inf, 0};
for (int k = opt[j]; k <= opt[j + 1]; k++) {
mn = min(mn, {nds[x << 1][i][k] + nds[x << 1 | 1][k][j], -k});
}
nds[x][i][j] = mn[0];
opt[j] = -mn[1];
}
}
}
void init(int r, int c, int H[mxR][mxC], int V[mxR][mxC]) {
for (int i = 0; i < mxR; i++) {
for (int j = 0; j < mxC; j++) {
h[i][j] = inf;
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c - 1; j++) {
h[i][j] = H[i][j];
}
}
for (int i = 0; i < r - 1; i++) {
for (int j = 0; j < c; j++) {
v[i][j] = V[i][j];
}
}
opt[mxC] = mxC - 1;
build(1, 0, mxN - 1);
upd(1, 0, mxN - 1);
}
void changeH(int x, int y, int w) {
h[x][y] = w;
upd(1, x / bs, x / bs);
}
void changeV(int x, int y, int w) {
v[x][y] = w;
upd(1, x / bs, x / bs);
}
int escape(int x, int y) {
return nds[1][x][y];
}
/*
int main() {
cin.tie(0)->sync_with_stdio(0);
int r, c; cin >> r >> c;
int h[r][200], v[r][200];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c - 1; j++) {
cin >> h[i][j];
}
}
for (int i = 0; i < r - 1; i++) {
for (int j = 0; j < c; j++) {
cin >> v[i][j];
}
}
init(r, c, h, v);
int q; cin >> q;
while (q--) {
int type, x, y, w; cin >> type;
if (type == 3) {
cin >> x >> y;
cout << escape(x, y) << "\n";
}
else {
cin >> x >> y >> w;
//continue;
if (type == 1) {
changeH(x, y, w);
}
else {
changeV(x, y, w);
}
}
}
return 0;
}
*/
/*
3 4
0 2 5
7 1 1
0 4 0
0 0 0 2
0 3 4 7
5
3 2 1
3 3 3
2 0 0 5
1 1 1 6
3 2 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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4056 ms |
90204 KB |
Output is correct |
2 |
Correct |
4051 ms |
90284 KB |
Output is correct |
3 |
Correct |
4030 ms |
92960 KB |
Output is correct |
4 |
Correct |
3983 ms |
90324 KB |
Output is correct |
5 |
Correct |
3963 ms |
90336 KB |
Output is correct |
6 |
Correct |
1133 ms |
82308 KB |
Output is correct |
7 |
Correct |
1132 ms |
82432 KB |
Output is correct |
8 |
Correct |
1137 ms |
82368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1163 ms |
82372 KB |
Output is correct |
2 |
Correct |
1139 ms |
82328 KB |
Output is correct |
3 |
Correct |
1137 ms |
82428 KB |
Output is correct |
4 |
Correct |
1142 ms |
82600 KB |
Output is correct |
5 |
Correct |
1143 ms |
82460 KB |
Output is correct |
6 |
Correct |
1128 ms |
82432 KB |
Output is correct |
7 |
Correct |
1138 ms |
82328 KB |
Output is correct |
8 |
Correct |
1135 ms |
82640 KB |
Output is correct |
9 |
Correct |
1128 ms |
82656 KB |
Output is correct |
10 |
Correct |
1135 ms |
82352 KB |
Output is correct |
11 |
Correct |
1196 ms |
84684 KB |
Output is correct |
12 |
Correct |
1142 ms |
82540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1703 ms |
82724 KB |
Output is correct |
2 |
Correct |
1691 ms |
82768 KB |
Output is correct |
3 |
Correct |
1707 ms |
82792 KB |
Output is correct |
4 |
Correct |
1701 ms |
82640 KB |
Output is correct |
5 |
Correct |
1682 ms |
82864 KB |
Output is correct |
6 |
Correct |
1137 ms |
82528 KB |
Output is correct |
7 |
Correct |
1133 ms |
82504 KB |
Output is correct |
8 |
Correct |
1141 ms |
82384 KB |
Output is correct |
9 |
Correct |
3908 ms |
82736 KB |
Output is correct |
10 |
Correct |
1147 ms |
82376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3959 ms |
94256 KB |
Output is correct |
2 |
Correct |
4013 ms |
94280 KB |
Output is correct |
3 |
Correct |
4010 ms |
94172 KB |
Output is correct |
4 |
Correct |
4059 ms |
95588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1730 ms |
82884 KB |
Output is correct |
2 |
Correct |
1731 ms |
82796 KB |
Output is correct |
3 |
Correct |
1697 ms |
82928 KB |
Output is correct |
4 |
Correct |
1701 ms |
82788 KB |
Output is correct |
5 |
Correct |
1690 ms |
82692 KB |
Output is correct |
6 |
Correct |
4018 ms |
94324 KB |
Output is correct |
7 |
Correct |
3994 ms |
94316 KB |
Output is correct |
8 |
Correct |
4074 ms |
94216 KB |
Output is correct |
9 |
Correct |
4011 ms |
95696 KB |
Output is correct |
10 |
Correct |
3961 ms |
90196 KB |
Output is correct |
11 |
Correct |
4035 ms |
90364 KB |
Output is correct |
12 |
Correct |
4057 ms |
93028 KB |
Output is correct |
13 |
Correct |
3987 ms |
90312 KB |
Output is correct |
14 |
Correct |
3977 ms |
90456 KB |
Output is correct |
15 |
Correct |
1163 ms |
82440 KB |
Output is correct |
16 |
Correct |
1154 ms |
82312 KB |
Output is correct |
17 |
Correct |
1155 ms |
82432 KB |
Output is correct |
18 |
Correct |
1145 ms |
82344 KB |
Output is correct |
19 |
Correct |
1135 ms |
82456 KB |
Output is correct |
20 |
Correct |
1137 ms |
82500 KB |
Output is correct |
21 |
Correct |
1140 ms |
82420 KB |
Output is correct |
22 |
Correct |
1131 ms |
82328 KB |
Output is correct |
23 |
Correct |
1135 ms |
82412 KB |
Output is correct |
24 |
Correct |
1144 ms |
82392 KB |
Output is correct |
25 |
Correct |
1198 ms |
84828 KB |
Output is correct |
26 |
Correct |
1139 ms |
82504 KB |
Output is correct |
27 |
Correct |
3946 ms |
82716 KB |
Output is correct |
28 |
Correct |
4072 ms |
98312 KB |
Output is correct |
29 |
Correct |
4083 ms |
95960 KB |
Output is correct |
30 |
Correct |
4127 ms |
96136 KB |
Output is correct |
31 |
Correct |
4115 ms |
99884 KB |
Output is correct |
32 |
Correct |
1151 ms |
82304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1715 ms |
82760 KB |
Output is correct |
2 |
Correct |
1716 ms |
82756 KB |
Output is correct |
3 |
Correct |
1777 ms |
82696 KB |
Output is correct |
4 |
Correct |
1711 ms |
82664 KB |
Output is correct |
5 |
Correct |
1700 ms |
82688 KB |
Output is correct |
6 |
Correct |
3987 ms |
94236 KB |
Output is correct |
7 |
Correct |
4003 ms |
94228 KB |
Output is correct |
8 |
Correct |
3991 ms |
94168 KB |
Output is correct |
9 |
Correct |
4026 ms |
95432 KB |
Output is correct |
10 |
Correct |
3991 ms |
90308 KB |
Output is correct |
11 |
Correct |
3956 ms |
90220 KB |
Output is correct |
12 |
Correct |
4045 ms |
93040 KB |
Output is correct |
13 |
Correct |
4022 ms |
90220 KB |
Output is correct |
14 |
Correct |
3965 ms |
90304 KB |
Output is correct |
15 |
Correct |
1301 ms |
103796 KB |
Output is correct |
16 |
Correct |
4306 ms |
105112 KB |
Output is correct |
17 |
Correct |
1130 ms |
82368 KB |
Output is correct |
18 |
Correct |
1146 ms |
82268 KB |
Output is correct |
19 |
Correct |
1161 ms |
82448 KB |
Output is correct |
20 |
Correct |
1151 ms |
82388 KB |
Output is correct |
21 |
Correct |
1164 ms |
82320 KB |
Output is correct |
22 |
Correct |
1146 ms |
82508 KB |
Output is correct |
23 |
Correct |
1138 ms |
82504 KB |
Output is correct |
24 |
Correct |
1136 ms |
82484 KB |
Output is correct |
25 |
Correct |
1146 ms |
82452 KB |
Output is correct |
26 |
Correct |
1145 ms |
82388 KB |
Output is correct |
27 |
Correct |
1215 ms |
84896 KB |
Output is correct |
28 |
Correct |
1154 ms |
82496 KB |
Output is correct |
29 |
Correct |
3926 ms |
82736 KB |
Output is correct |
30 |
Correct |
4030 ms |
98772 KB |
Output is correct |
31 |
Correct |
3995 ms |
102512 KB |
Output is correct |
32 |
Correct |
4082 ms |
102856 KB |
Output is correct |
33 |
Correct |
4042 ms |
96012 KB |
Output is correct |
34 |
Correct |
4174 ms |
100012 KB |
Output is correct |
35 |
Correct |
4057 ms |
95988 KB |
Output is correct |
36 |
Correct |
4211 ms |
100112 KB |
Output is correct |
37 |
Correct |
4129 ms |
100080 KB |
Output is correct |
38 |
Correct |
4045 ms |
103072 KB |
Output is correct |
39 |
Correct |
1159 ms |
82492 KB |
Output is correct |
40 |
Correct |
4401 ms |
100236 KB |
Output is correct |