#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int sz=15,INF=2e9;
int r,c,row,h[5000][200],v[5000][200],st[20000/sz+5][200][200];
void dnc(int node, int l, int r, int i, int optl, int optr){
if (l>r)
return;
if (optl==optr){
for (int j=l;j<=r;j++)
st[node][i][j]=st[node<<1][i][optl]+st[node<<1|1][optl][j];
return;
}
int mid=(l+r)>>1;
pair <int, int> p={INF,-1};
for (int j=optl;j<=optr;j++)
p=min(p,{st[node<<1][i][j]+st[node<<1|1][j][mid],j});
st[node][i][mid]=p.first;
dnc(node,l,mid-1,i,optl,p.second);
dnc(node,mid+1,r,i,p.second,optr);
}
void update(int node, int l, int r, int x, int y){
if (l>y||r<x)
return;
if (l==r){
for (int i=0;i<c;i++)
for (int j=0;j<c;j++)
st[node][i][j]=(i==j?0:INF);
for (int k=l*sz;k<min(l*sz+sz,row);k++){
for (int i=0;i<c;i++){
for (int j=1;j<c;j++)
st[node][i][j]=min(st[node][i][j],st[node][i][j-1]+h[k][j-1]);
for (int j=c-2;j>=0;j--)
st[node][i][j]=min(st[node][i][j],st[node][i][j+1]+h[k][j]);
for (int j=0;j<c;j++)
st[node][i][j]+=v[k][j];
}
}
return;
}
int mid=(l+r)>>1;
update(node<<1,l,mid,x,y);
update(node<<1|1,mid+1,r,x,y);
for (int i=0;i<c;i++)
dnc(node,0,c-1,i,0,c-1);
}
void init(int R, int C, int H[5000][200], int V[5000][200]){
row=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];
update(1,0,(r-1)/sz,0,r-1);
}
void changeH(int P, int Q, int W){
h[P][Q]=W;
update(1,0,(r-1)/sz,P/sz,P/sz);
}
void changeV(int P, int Q, int W){
v[P][Q]=W;
update(1,0,(r-1)/sz,P/sz,P/sz);
}
int escape(int V1, int V2){
return st[1][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 |
19 ms |
172888 KB |
Output is correct |
2 |
Correct |
19 ms |
172892 KB |
Output is correct |
3 |
Correct |
74 ms |
174420 KB |
Output is correct |
4 |
Correct |
20 ms |
172892 KB |
Output is correct |
5 |
Correct |
20 ms |
172892 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4592 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8536 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
61 ms |
9468 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
10756 KB |
Output is correct |
2 |
Correct |
148 ms |
10752 KB |
Output is correct |
3 |
Correct |
158 ms |
10772 KB |
Output is correct |
4 |
Correct |
173 ms |
10756 KB |
Output is correct |
5 |
Correct |
161 ms |
10588 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
721 ms |
10752 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
178268 KB |
Output is correct |
2 |
Correct |
19 ms |
178288 KB |
Output is correct |
3 |
Correct |
20 ms |
178268 KB |
Output is correct |
4 |
Correct |
45 ms |
179028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
10588 KB |
Output is correct |
2 |
Correct |
147 ms |
10584 KB |
Output is correct |
3 |
Correct |
157 ms |
10760 KB |
Output is correct |
4 |
Correct |
162 ms |
10772 KB |
Output is correct |
5 |
Correct |
158 ms |
10776 KB |
Output is correct |
6 |
Correct |
20 ms |
178264 KB |
Output is correct |
7 |
Correct |
20 ms |
178300 KB |
Output is correct |
8 |
Correct |
20 ms |
178268 KB |
Output is correct |
9 |
Correct |
55 ms |
179028 KB |
Output is correct |
10 |
Correct |
20 ms |
172892 KB |
Output is correct |
11 |
Correct |
19 ms |
172892 KB |
Output is correct |
12 |
Correct |
69 ms |
174548 KB |
Output is correct |
13 |
Correct |
20 ms |
172892 KB |
Output is correct |
14 |
Correct |
21 ms |
172892 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8536 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
54 ms |
9440 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
731 ms |
10756 KB |
Output is correct |
28 |
Correct |
1587 ms |
178688 KB |
Output is correct |
29 |
Correct |
1493 ms |
134768 KB |
Output is correct |
30 |
Correct |
1548 ms |
137244 KB |
Output is correct |
31 |
Correct |
1539 ms |
179664 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
10588 KB |
Output is correct |
2 |
Correct |
152 ms |
10756 KB |
Output is correct |
3 |
Correct |
158 ms |
10588 KB |
Output is correct |
4 |
Correct |
161 ms |
10756 KB |
Output is correct |
5 |
Correct |
165 ms |
10756 KB |
Output is correct |
6 |
Correct |
19 ms |
178264 KB |
Output is correct |
7 |
Correct |
19 ms |
178268 KB |
Output is correct |
8 |
Correct |
19 ms |
178268 KB |
Output is correct |
9 |
Correct |
54 ms |
179028 KB |
Output is correct |
10 |
Correct |
17 ms |
172888 KB |
Output is correct |
11 |
Correct |
17 ms |
172892 KB |
Output is correct |
12 |
Correct |
73 ms |
174508 KB |
Output is correct |
13 |
Correct |
19 ms |
172888 KB |
Output is correct |
14 |
Correct |
17 ms |
172888 KB |
Output is correct |
15 |
Correct |
1846 ms |
178272 KB |
Output is correct |
16 |
Correct |
6690 ms |
179940 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
8536 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8536 KB |
Output is correct |
24 |
Correct |
2 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8536 KB |
Output is correct |
27 |
Correct |
55 ms |
9556 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
727 ms |
10756 KB |
Output is correct |
30 |
Correct |
1493 ms |
178688 KB |
Output is correct |
31 |
Correct |
5849 ms |
179128 KB |
Output is correct |
32 |
Correct |
5829 ms |
179500 KB |
Output is correct |
33 |
Correct |
1505 ms |
135124 KB |
Output is correct |
34 |
Correct |
6095 ms |
137808 KB |
Output is correct |
35 |
Correct |
1625 ms |
136728 KB |
Output is correct |
36 |
Correct |
6127 ms |
139696 KB |
Output is correct |
37 |
Correct |
1557 ms |
179652 KB |
Output is correct |
38 |
Correct |
5970 ms |
179988 KB |
Output is correct |
39 |
Correct |
1 ms |
8540 KB |
Output is correct |
40 |
Correct |
6436 ms |
139664 KB |
Output is correct |