#include "wombats.h"
#include <bits/stdc++.h>
#define R 5005
#define C 205
using namespace std;
const int block = 40;
int r,c;
int h[R][C];
int w[R][C];
int opt[C][C];
struct node{
int a[C][C];
int l,r;
node(int init){
for(int i = 0;i<C;i++){
for(int j = 0;j<C;j++){
a[i][j] = init;
}
}
}
}tmp(0);
node merge(node a,node b){
for(int dif = -c-1;dif < c ;dif++){
for(int i = max(0,-dif);i + max(0,dif)<c;i++){
int j = dif + i;
int l = 0,r = c-1;
if(j)
l = opt[i][j-1];
if(i + 1 != c)
r = opt[i+1][j];
tmp.a[i][j] = 1e9;
for(int x = l;x<=r;x++){
if(a.a[i][x] + b.a[x][j] < tmp.a[i][j]){
tmp.a[i][j] = a.a[i][x] + b.a[x][j];
opt[i][j] = x;
}
}
}
}
return tmp;
}
struct SegTree{
vector<node> t;
int n;
void init(int size){
n = size;
t.assign(4*n + 5,1e9);
build(1,0,n-1);
}
void build(int v,int tl,int tr){
t[v].l = tl * block;
t[v].r = min(r-1,(tr + 1) * block - 1);
if(tl == tr){
for(int i = 0;i<c;i++){
t[v].a[i][i] = 0;
for(int j = t[v].l;j<=t[v].r;j++){
for(int d=1;d<c;d++){
t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d-1] + h[j][d-1]);
}
for(int d=c-2;d>=0;d--){
t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d+1] + h[j][d]);
}
for(int d=0;d<c;d++){
t[v].a[i][d] = t[v].a[i][d] + w[j][d];
}
}
}
return;
}
int tm = (tl + tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
t[v] = merge(t[v*2],t[v*2+1]);
}
void upd(int v,int tl,int tr,int pos){
if(tl == tr){
for(int i = 0;i<c;i++){
t[v].a[i][i] = 0;
for(int j = t[v].l;j<=t[v].r;j++){
for(int d=1;d<c;d++){
t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d-1] + h[j][d-1]);
}
for(int d=c-2;d>=0;d--){
t[v].a[i][d] = min(t[v].a[i][d],t[v].a[i][d+1] + h[j][d]);
}
for(int d=0;d<c;d++){
t[v].a[i][d] = t[v].a[i][d] + w[j][d];
}
}
}
return;
}
int tm = (tl + tr)/2;
if(pos <= tm)
upd(v*2,tl,tm,pos);
else upd(v*2+1,tm+1,tr,pos);
t[v] = merge(t[v*2],t[v*2+1]);
}
void upd(int pos){
upd(1,0,n-1,pos);
}
}tree;
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;j++){
h[i][j] = h_[i][j];
w[i][j] = v_[i][j];
}
}
tree.init((r+block-1) / block);
}
void changeH(int p, int q, int x) {
h[p][q] = x;
tree.upd(p/block);
}
void changeV(int p, int q, int x) {
w[p][q] = x;
if(p % block == 0 && p)
tree.upd(p/block - 1);
tree.upd(p/block);
}
int escape(int v1, int v2) {
return tree.t[1].a[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 |
147 ms |
96864 KB |
Output is correct |
2 |
Correct |
147 ms |
96920 KB |
Output is correct |
3 |
Correct |
212 ms |
98496 KB |
Output is correct |
4 |
Correct |
170 ms |
96960 KB |
Output is correct |
5 |
Correct |
150 ms |
96944 KB |
Output is correct |
6 |
Correct |
1 ms |
2132 KB |
Output is correct |
7 |
Correct |
1 ms |
2132 KB |
Output is correct |
8 |
Correct |
1 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2132 KB |
Output is correct |
2 |
Correct |
2 ms |
2132 KB |
Output is correct |
3 |
Correct |
2 ms |
2132 KB |
Output is correct |
4 |
Correct |
1 ms |
2132 KB |
Output is correct |
5 |
Correct |
2 ms |
2132 KB |
Output is correct |
6 |
Correct |
1 ms |
2132 KB |
Output is correct |
7 |
Correct |
1 ms |
2132 KB |
Output is correct |
8 |
Correct |
1 ms |
2132 KB |
Output is correct |
9 |
Correct |
1 ms |
2132 KB |
Output is correct |
10 |
Correct |
1 ms |
2132 KB |
Output is correct |
11 |
Correct |
66 ms |
3148 KB |
Output is correct |
12 |
Correct |
1 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
228 ms |
4240 KB |
Output is correct |
2 |
Correct |
327 ms |
4308 KB |
Output is correct |
3 |
Correct |
305 ms |
4356 KB |
Output is correct |
4 |
Correct |
310 ms |
4308 KB |
Output is correct |
5 |
Correct |
329 ms |
4232 KB |
Output is correct |
6 |
Correct |
1 ms |
2132 KB |
Output is correct |
7 |
Correct |
1 ms |
2132 KB |
Output is correct |
8 |
Correct |
1 ms |
2132 KB |
Output is correct |
9 |
Correct |
1593 ms |
4360 KB |
Output is correct |
10 |
Correct |
1 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
100880 KB |
Output is correct |
2 |
Correct |
156 ms |
100868 KB |
Output is correct |
3 |
Correct |
174 ms |
100980 KB |
Output is correct |
4 |
Correct |
175 ms |
101564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
4308 KB |
Output is correct |
2 |
Correct |
327 ms |
4308 KB |
Output is correct |
3 |
Correct |
311 ms |
4308 KB |
Output is correct |
4 |
Correct |
311 ms |
4308 KB |
Output is correct |
5 |
Correct |
332 ms |
4308 KB |
Output is correct |
6 |
Correct |
145 ms |
100744 KB |
Output is correct |
7 |
Correct |
155 ms |
100860 KB |
Output is correct |
8 |
Correct |
162 ms |
100864 KB |
Output is correct |
9 |
Correct |
192 ms |
101604 KB |
Output is correct |
10 |
Correct |
153 ms |
96840 KB |
Output is correct |
11 |
Correct |
147 ms |
96864 KB |
Output is correct |
12 |
Correct |
198 ms |
98564 KB |
Output is correct |
13 |
Correct |
155 ms |
96852 KB |
Output is correct |
14 |
Correct |
137 ms |
96980 KB |
Output is correct |
15 |
Correct |
1 ms |
2132 KB |
Output is correct |
16 |
Correct |
1 ms |
2132 KB |
Output is correct |
17 |
Correct |
1 ms |
2132 KB |
Output is correct |
18 |
Correct |
1 ms |
2132 KB |
Output is correct |
19 |
Correct |
1 ms |
2132 KB |
Output is correct |
20 |
Correct |
2 ms |
2132 KB |
Output is correct |
21 |
Correct |
1 ms |
2132 KB |
Output is correct |
22 |
Correct |
1 ms |
2132 KB |
Output is correct |
23 |
Correct |
1 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
2132 KB |
Output is correct |
25 |
Correct |
68 ms |
3308 KB |
Output is correct |
26 |
Correct |
1 ms |
2132 KB |
Output is correct |
27 |
Correct |
1604 ms |
4236 KB |
Output is correct |
28 |
Correct |
2336 ms |
101476 KB |
Output is correct |
29 |
Correct |
2262 ms |
84080 KB |
Output is correct |
30 |
Correct |
2261 ms |
83952 KB |
Output is correct |
31 |
Correct |
2385 ms |
102316 KB |
Output is correct |
32 |
Correct |
1 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
4332 KB |
Output is correct |
2 |
Correct |
325 ms |
4360 KB |
Output is correct |
3 |
Correct |
310 ms |
4308 KB |
Output is correct |
4 |
Correct |
309 ms |
4236 KB |
Output is correct |
5 |
Correct |
330 ms |
4308 KB |
Output is correct |
6 |
Correct |
157 ms |
100868 KB |
Output is correct |
7 |
Correct |
160 ms |
100824 KB |
Output is correct |
8 |
Correct |
175 ms |
100840 KB |
Output is correct |
9 |
Correct |
191 ms |
101584 KB |
Output is correct |
10 |
Correct |
139 ms |
96904 KB |
Output is correct |
11 |
Correct |
149 ms |
96952 KB |
Output is correct |
12 |
Correct |
209 ms |
98624 KB |
Output is correct |
13 |
Correct |
156 ms |
96856 KB |
Output is correct |
14 |
Correct |
155 ms |
96872 KB |
Output is correct |
15 |
Correct |
1770 ms |
101092 KB |
Output is correct |
16 |
Correct |
8848 ms |
111920 KB |
Output is correct |
17 |
Correct |
1 ms |
2132 KB |
Output is correct |
18 |
Correct |
1 ms |
2132 KB |
Output is correct |
19 |
Correct |
1 ms |
2132 KB |
Output is correct |
20 |
Correct |
2 ms |
2144 KB |
Output is correct |
21 |
Correct |
2 ms |
2132 KB |
Output is correct |
22 |
Correct |
1 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
2132 KB |
Output is correct |
25 |
Correct |
1 ms |
2132 KB |
Output is correct |
26 |
Correct |
2 ms |
2144 KB |
Output is correct |
27 |
Correct |
65 ms |
4464 KB |
Output is correct |
28 |
Correct |
1 ms |
2132 KB |
Output is correct |
29 |
Correct |
1604 ms |
4308 KB |
Output is correct |
30 |
Correct |
2328 ms |
105036 KB |
Output is correct |
31 |
Correct |
8591 ms |
109384 KB |
Output is correct |
32 |
Correct |
8641 ms |
109556 KB |
Output is correct |
33 |
Correct |
2265 ms |
87444 KB |
Output is correct |
34 |
Correct |
8423 ms |
91696 KB |
Output is correct |
35 |
Correct |
2238 ms |
87496 KB |
Output is correct |
36 |
Correct |
8540 ms |
91476 KB |
Output is correct |
37 |
Correct |
2383 ms |
106784 KB |
Output is correct |
38 |
Correct |
8656 ms |
110012 KB |
Output is correct |
39 |
Correct |
1 ms |
2132 KB |
Output is correct |
40 |
Correct |
8724 ms |
91676 KB |
Output is correct |