#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 {
vector<vector<int>> dis;
int r;
void init() {
dis.assign(m, vector<int>(m, 1e9));
}
A operator + (const A& o) const {
A res;
res.init();
for (int i = 0;i < m;i++) {
for (int j = 0;j < m;j++) {
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;
}
};
vector<A> tree;
void build(int now = 1, int l = 0, int r = n - 1) {
if (l == r) {
tree[now].init();
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];
}
}
tree.resize(4 * n);
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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7516 KB |
Output is correct |
2 |
Correct |
5 ms |
7464 KB |
Output is correct |
3 |
Correct |
42 ms |
9052 KB |
Output is correct |
4 |
Correct |
5 ms |
7512 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
43 ms |
1476 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
933 ms |
9044 KB |
Output is correct |
2 |
Correct |
928 ms |
9132 KB |
Output is correct |
3 |
Correct |
995 ms |
9108 KB |
Output is correct |
4 |
Correct |
1029 ms |
9300 KB |
Output is correct |
5 |
Correct |
978 ms |
9092 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 |
4399 ms |
9304 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
14072 KB |
Output is correct |
2 |
Correct |
12 ms |
13912 KB |
Output is correct |
3 |
Correct |
8 ms |
13916 KB |
Output is correct |
4 |
Correct |
28 ms |
14840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1022 ms |
9220 KB |
Output is correct |
2 |
Correct |
967 ms |
9044 KB |
Output is correct |
3 |
Correct |
1031 ms |
9244 KB |
Output is correct |
4 |
Correct |
1000 ms |
9304 KB |
Output is correct |
5 |
Correct |
914 ms |
9040 KB |
Output is correct |
6 |
Correct |
15 ms |
13912 KB |
Output is correct |
7 |
Correct |
8 ms |
13916 KB |
Output is correct |
8 |
Correct |
14 ms |
13916 KB |
Output is correct |
9 |
Correct |
56 ms |
14720 KB |
Output is correct |
10 |
Correct |
5 ms |
7516 KB |
Output is correct |
11 |
Correct |
5 ms |
7512 KB |
Output is correct |
12 |
Correct |
86 ms |
8980 KB |
Output is correct |
13 |
Correct |
6 ms |
7516 KB |
Output is correct |
14 |
Correct |
8 ms |
7516 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
41 ms |
1420 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
4274 ms |
9300 KB |
Output is correct |
28 |
Runtime error |
3713 ms |
262144 KB |
Execution killed with signal 9 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
943 ms |
9216 KB |
Output is correct |
2 |
Correct |
939 ms |
9136 KB |
Output is correct |
3 |
Correct |
966 ms |
9304 KB |
Output is correct |
4 |
Correct |
956 ms |
9300 KB |
Output is correct |
5 |
Correct |
966 ms |
9220 KB |
Output is correct |
6 |
Correct |
13 ms |
13912 KB |
Output is correct |
7 |
Correct |
8 ms |
13916 KB |
Output is correct |
8 |
Correct |
15 ms |
13916 KB |
Output is correct |
9 |
Correct |
53 ms |
14672 KB |
Output is correct |
10 |
Correct |
7 ms |
7516 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
44 ms |
9164 KB |
Output is correct |
13 |
Correct |
5 ms |
7512 KB |
Output is correct |
14 |
Correct |
5 ms |
7516 KB |
Output is correct |
15 |
Runtime error |
7670 ms |
262144 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |