#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5000;
const int M = 100;
int rc[N][M]; // cost from (i, j) -> (i+1, j)
int cc[N][M]; // cost from (i, j) -> (i, j+1)
int n, m;
struct A {
int dis[M][M], r;
A operator + (const A& o) const {
A res;
for (int i = 0;i < m;i++) {
for (int j = 0;j < m;j++) {
res.dis[i][j] = 1e9;
for (int k = 0;k < m;k++) {
res.dis[i][j] = min(res.dis[i][j],
dis[i][k] + rc[r][k] + o.dis[k][j]);
}
}
}
res.r = o.r;
return res;
}
} tree[(1 << 14) + 1];
void build(int now = 1, int l = 0, int r = n - 1) {
if (l == r) {
vector<int> sum(m);
sum[0] = 0;
for (int i = 1;i < m;i++) {
sum[i] = sum[i - 1] + cc[l][i - 1];
}
for (int i = 0;i < m;i++) {
for (int j = i;j < m;j++) {
tree[now].dis[i][j] = tree[now].dis[j][i] = sum[j] - sum[i];
}
}
tree[now].r = r;
return;
}
int mid = (l + r) / 2;
build(2 * now, l, mid), build(2 * now + 1, mid + 1, r);
tree[now] = tree[2 * now] + tree[2 * now + 1];
};
void update(int v, int now = 1, int l = 0, int r = n - 1) {
if (l == r) {
vector<int> sum(m);
sum[0] = 0;
for (int i = 1;i < m;i++) {
sum[i] = sum[i - 1] + cc[l][i - 1];
}
for (int i = 0;i < m;i++) {
for (int j = i;j < m;j++) {
tree[now].dis[i][j] = tree[now].dis[j][i] = sum[j] - sum[i];
}
}
tree[now].r = r;
return;
}
int mid = (l + r) / 2;
if (v <= mid) update(v, 2 * now, l, mid);
else update(v, 2 * now + 1, mid + 1, r);
tree[now] = tree[2 * now] + tree[2 * now + 1];
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R, m = C;
for (int i = 0;i < n - 1;i++) {
for (int j = 0;j < m;j++) {
rc[i][j] = V[i][j];
}
}
for (int i = 0;i < n;i++) {
for (int j = 0;j < m - 1;j++) {
cc[i][j] = H[i][j];
}
}
build();
}
void changeH(int P, int Q, int W) {
cc[P][Q] = W;
update(P);
}
void changeV(int P, int Q, int W) {
rc[P][Q] = W;
update(P);
}
int escape(int V1, int V2) {
return tree[1].dis[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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
226900 KB |
Output is correct |
2 |
Correct |
135 ms |
226896 KB |
Output is correct |
3 |
Correct |
164 ms |
229568 KB |
Output is correct |
4 |
Correct |
110 ms |
226900 KB |
Output is correct |
5 |
Correct |
128 ms |
227012 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
2 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1732 KB |
Output is correct |
11 |
Correct |
64 ms |
3664 KB |
Output is correct |
12 |
Correct |
2 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
687 ms |
8792 KB |
Output is correct |
2 |
Correct |
587 ms |
8788 KB |
Output is correct |
3 |
Correct |
648 ms |
8908 KB |
Output is correct |
4 |
Correct |
710 ms |
8888 KB |
Output is correct |
5 |
Correct |
726 ms |
8900 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2800 ms |
9116 KB |
Output is correct |
10 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
234504 KB |
Output is correct |
2 |
Correct |
114 ms |
234576 KB |
Output is correct |
3 |
Correct |
121 ms |
234576 KB |
Output is correct |
4 |
Correct |
150 ms |
235364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
594 ms |
8828 KB |
Output is correct |
2 |
Correct |
574 ms |
8788 KB |
Output is correct |
3 |
Correct |
587 ms |
9040 KB |
Output is correct |
4 |
Correct |
634 ms |
8908 KB |
Output is correct |
5 |
Correct |
564 ms |
8812 KB |
Output is correct |
6 |
Correct |
116 ms |
234580 KB |
Output is correct |
7 |
Correct |
119 ms |
234576 KB |
Output is correct |
8 |
Correct |
116 ms |
234576 KB |
Output is correct |
9 |
Correct |
125 ms |
235344 KB |
Output is correct |
10 |
Correct |
111 ms |
226896 KB |
Output is correct |
11 |
Correct |
113 ms |
226900 KB |
Output is correct |
12 |
Correct |
142 ms |
228432 KB |
Output is correct |
13 |
Correct |
133 ms |
226896 KB |
Output is correct |
14 |
Correct |
109 ms |
226960 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
1 ms |
1628 KB |
Output is correct |
22 |
Correct |
1 ms |
1624 KB |
Output is correct |
23 |
Correct |
1 ms |
1628 KB |
Output is correct |
24 |
Correct |
1 ms |
1628 KB |
Output is correct |
25 |
Correct |
40 ms |
2640 KB |
Output is correct |
26 |
Correct |
1 ms |
1624 KB |
Output is correct |
27 |
Correct |
2641 ms |
8704 KB |
Output is correct |
28 |
Runtime error |
2557 ms |
262144 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
587 ms |
8820 KB |
Output is correct |
2 |
Correct |
638 ms |
8888 KB |
Output is correct |
3 |
Correct |
605 ms |
8884 KB |
Output is correct |
4 |
Correct |
586 ms |
8784 KB |
Output is correct |
5 |
Correct |
593 ms |
9040 KB |
Output is correct |
6 |
Correct |
106 ms |
234532 KB |
Output is correct |
7 |
Correct |
108 ms |
234784 KB |
Output is correct |
8 |
Correct |
116 ms |
234576 KB |
Output is correct |
9 |
Correct |
126 ms |
235468 KB |
Output is correct |
10 |
Correct |
123 ms |
226900 KB |
Output is correct |
11 |
Correct |
103 ms |
226904 KB |
Output is correct |
12 |
Correct |
170 ms |
228432 KB |
Output is correct |
13 |
Correct |
111 ms |
226804 KB |
Output is correct |
14 |
Correct |
103 ms |
226900 KB |
Output is correct |
15 |
Runtime error |
165 ms |
21100 KB |
Execution killed with signal 6 |
16 |
Halted |
0 ms |
0 KB |
- |