#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 20;
const int maxN = 1e3 + 20;
const int maxM = 2e2 + 20;
const int block = 1;
int hor[maxN][maxM];
int ver[maxN][maxM];
int tmp[maxN][maxM];
int dp[maxN][maxM];
int tree[maxN / block * 4][maxM][maxM];
int N, M;
void calc(int id, int lt, int rt) {
for (int X = 0; X < M; X++) {
dp[lt][X] = 0;
for (int i = X - 1; i >= 0; i--) {
dp[lt][i] = dp[lt][i + 1] + hor[lt][i];
}
for (int i = X + 1; i < M; i++) {
dp[lt][i] = dp[lt][i - 1] + hor[lt][i - 1];
}
for (int i = lt + 1; i <= rt; i++) {
for (int j = 0; j < M; j++) {
tmp[i][j] = dp[i - 1][j] + ver[i - 1][j];
dp[i][j] = tmp[i][j];
}
int best = tmp[i][0];
for (int j = 1; j < M; j++) {
best = min(best + hor[i][j - 1], tmp[i][j]);
dp[i][j] = min(dp[i][j], best);
}
best = tmp[i][M - 1];
for (int j = M - 2; j >= 0; j--) {
best = min(best + hor[i][j], tmp[i][j]);
dp[i][j] = min(dp[i][j], best);
}
}
for (int Y = 0; Y < M; Y++) {
tree[id][X][Y] = dp[rt][Y];
}
}
}
void merge(int id, int mt) {
for (int X = 0; X < M; X++) {
for (int Y = 0; Y < M; Y++) {
tree[id][X][Y] = inf;
}
}
for (int X = 0; X < M; X++) {
for (int Y = 0; Y < M; Y++) {
for (int Z = 0; Z < M; Z++) {
tree[id][X][Z] = min(tree[id][X][Z], tree[id * 2][X][Y] + ver[mt][Y] + tree[id * 2 + 1][Y][Z]);
}
}
}
}
void build(int id, int lt, int rt) {
if (lt == rt) {
calc(id, lt * block, min(N - 1, lt * block + block - 1));
return;
}
int mt = (lt + rt) / 2;
build(id * 2, lt, mt);
build(id * 2 + 1, mt + 1, rt);
merge(id, mt);
}
void update(int id, int lt, int rt, int pos) {
if (lt == rt) {
calc(id, lt * block, min(N - 1, lt * block + block - 1));
return;
}
int mt = (lt + rt) / 2;
if (pos <= mt) {
update(id * 2, lt, mt, pos);
}
else {
update(id * 2 + 1, mt + 1, rt, pos);
}
merge(id, mt);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
N = R;
M = C;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M - 1; j++) {
hor[i][j] = H[i][j];
}
}
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < M; j++) {
ver[i][j] = V[i][j];
}
}
build(1, 0, (N - 1) / block);
}
void changeH(int P, int Q, int W) {
hor[P][Q] = W;
update(1, 0, (N - 1) / block, P);
}
void changeV(int P, int Q, int W) {
ver[P][Q] = W;
update(1, 0, (N - 1) / block, P);
}
int escape(int X, int Y) {
return tree[1][X][Y];
}
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 |
Runtime error |
16 ms |
10068 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
58 ms |
2160 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
727 ms |
18456 KB |
Output is correct |
2 |
Correct |
716 ms |
18284 KB |
Output is correct |
3 |
Correct |
731 ms |
18632 KB |
Output is correct |
4 |
Correct |
749 ms |
18624 KB |
Output is correct |
5 |
Correct |
719 ms |
18472 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3288 ms |
18624 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
17028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
802 ms |
18440 KB |
Output is correct |
2 |
Correct |
717 ms |
18380 KB |
Output is correct |
3 |
Correct |
756 ms |
18624 KB |
Output is correct |
4 |
Correct |
739 ms |
18604 KB |
Output is correct |
5 |
Correct |
723 ms |
18464 KB |
Output is correct |
6 |
Runtime error |
21 ms |
17044 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
747 ms |
18440 KB |
Output is correct |
2 |
Correct |
713 ms |
18284 KB |
Output is correct |
3 |
Correct |
755 ms |
18620 KB |
Output is correct |
4 |
Correct |
746 ms |
18628 KB |
Output is correct |
5 |
Correct |
722 ms |
18464 KB |
Output is correct |
6 |
Runtime error |
20 ms |
17108 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |