#include <bits/stdc++.h>
#include "wombats.h"
using namespace std;
#define INF 2000000000
const int B = 20;
int h[5000][200], v[5000][200], bl[5000], br[5000], pos[5000], r, c;
struct node {
int s, e, m;
vector<vector<int>> f;
node *l, *r;
node(int _s, int _e) {
s = _s, e = _e, m = (s+e)/2;
for(int i = 0; i < 200; i++) {
vector<int> v(200);
f.push_back(v);
}
if(s != e) {
l = new node(s, m);
r = new node(m+1, e);
merge(l->f, r->f, f);
} else {
build(s);
}
}
void build(int s) {
for(int i = 0; i < c; i++) {
for(int j = i, res = 0; j < c; j++, res += h[bl[s]][j-1]) f[i][j] = res;
for(int j = i, res = 0; j >= 0; j--, res += h[bl[s]][j]) f[i][j] = res;
for(int j = 0; j < c; j++) f[i][j] += v[bl[s]][j];
for(int k = bl[s]+1; k <= br[s]; k++) {
for(int j = 1; j < c; j++) f[i][j] = min(f[i][j], f[i][j-1] + h[k][j-1]);
for(int j = c-2; j >= 0; j--) f[i][j] = min(f[i][j], f[i][j+1] + h[k][j]);
for(int j = 0; j < c; j++) f[i][j] += v[k][j];
}
}
}
void merge(vector<vector<int>> &a, vector<vector<int>> &b, vector<vector<int>> &f) {
for(int i = 0; i < c; i++) for(int j = 0; j < c; j++) f[i][j] = INF;
int p[c][c];
memset(p, -1, sizeof(p));
for(int i = 0; i < c; i++) {
for(int j = c-1; j >= 0; j--) {
int st = (i && p[i-1][j] != -1 ? p[i-1][j] : 0);
int ed = (j != c-1 && p[i][j+1] != -1 ? p[i][j+1] : c-1);
for(int k = st; k <= ed; k++) if(f[i][j] > a[i][k] + b[k][j]) {
f[i][j] = a[i][k] + b[k][j];
p[i][j] = k;
}
}
}
}
void update(int x) {
if(s == e) {build(s); return;}
else if(x > m) r->update(x);
else l->update(x);
merge(l->f, r->f, f);
}
} *root;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R; c = C;
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];
int cnt = (r-1)/B + 1;
for(int i = 0; i < cnt; i++) {
bl[i] = i*B;
br[i] = min((i+1)*B-1, r-1);
}
for(int i = 0; i < cnt; i++) {
for(int j = bl[i]; j <= br[i]; j++) pos[j] = i;
}
root = new node(0, cnt-1);
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
root->update(pos[P]);
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
root->update(pos[P]);
}
int escape(int V1, int V2) {
return root->f[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 |
40 ms |
91476 KB |
Output is correct |
2 |
Correct |
36 ms |
91468 KB |
Output is correct |
3 |
Correct |
75 ms |
94348 KB |
Output is correct |
4 |
Correct |
35 ms |
91476 KB |
Output is correct |
5 |
Correct |
34 ms |
91476 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
74 ms |
1624 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
2136 KB |
Output is correct |
2 |
Correct |
64 ms |
2140 KB |
Output is correct |
3 |
Correct |
68 ms |
2140 KB |
Output is correct |
4 |
Correct |
102 ms |
2136 KB |
Output is correct |
5 |
Correct |
73 ms |
2136 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
306 ms |
2140 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
99420 KB |
Output is correct |
2 |
Correct |
40 ms |
99408 KB |
Output is correct |
3 |
Correct |
63 ms |
99484 KB |
Output is correct |
4 |
Correct |
63 ms |
100920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
2140 KB |
Output is correct |
2 |
Correct |
65 ms |
2140 KB |
Output is correct |
3 |
Correct |
73 ms |
2308 KB |
Output is correct |
4 |
Correct |
67 ms |
2312 KB |
Output is correct |
5 |
Correct |
69 ms |
2312 KB |
Output is correct |
6 |
Correct |
40 ms |
99416 KB |
Output is correct |
7 |
Correct |
64 ms |
99412 KB |
Output is correct |
8 |
Correct |
40 ms |
99412 KB |
Output is correct |
9 |
Correct |
69 ms |
100948 KB |
Output is correct |
10 |
Correct |
40 ms |
91532 KB |
Output is correct |
11 |
Correct |
41 ms |
91532 KB |
Output is correct |
12 |
Correct |
80 ms |
94288 KB |
Output is correct |
13 |
Correct |
40 ms |
91476 KB |
Output is correct |
14 |
Correct |
39 ms |
91568 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
444 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 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 |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
42 ms |
2976 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
344 ms |
2164 KB |
Output is correct |
28 |
Correct |
625 ms |
103508 KB |
Output is correct |
29 |
Correct |
595 ms |
85332 KB |
Output is correct |
30 |
Correct |
609 ms |
85284 KB |
Output is correct |
31 |
Correct |
624 ms |
105296 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
2300 KB |
Output is correct |
2 |
Correct |
56 ms |
2140 KB |
Output is correct |
3 |
Correct |
73 ms |
2392 KB |
Output is correct |
4 |
Correct |
61 ms |
2136 KB |
Output is correct |
5 |
Correct |
60 ms |
2140 KB |
Output is correct |
6 |
Correct |
45 ms |
99416 KB |
Output is correct |
7 |
Correct |
41 ms |
99412 KB |
Output is correct |
8 |
Correct |
41 ms |
99416 KB |
Output is correct |
9 |
Correct |
61 ms |
100848 KB |
Output is correct |
10 |
Correct |
34 ms |
91608 KB |
Output is correct |
11 |
Correct |
35 ms |
91484 KB |
Output is correct |
12 |
Correct |
77 ms |
94340 KB |
Output is correct |
13 |
Correct |
38 ms |
91476 KB |
Output is correct |
14 |
Correct |
37 ms |
91472 KB |
Output is correct |
15 |
Correct |
631 ms |
109144 KB |
Output is correct |
16 |
Correct |
2307 ms |
110488 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
600 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 |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
41 ms |
3016 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
310 ms |
2644 KB |
Output is correct |
30 |
Correct |
600 ms |
103516 KB |
Output is correct |
31 |
Correct |
2213 ms |
108160 KB |
Output is correct |
32 |
Correct |
2410 ms |
107892 KB |
Output is correct |
33 |
Correct |
624 ms |
85328 KB |
Output is correct |
34 |
Correct |
2391 ms |
89428 KB |
Output is correct |
35 |
Correct |
659 ms |
85332 KB |
Output is correct |
36 |
Correct |
2247 ms |
89352 KB |
Output is correct |
37 |
Correct |
644 ms |
105296 KB |
Output is correct |
38 |
Correct |
2322 ms |
108628 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
2274 ms |
89668 KB |
Output is correct |