#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],opt;
void dnc(int node, int l, int r, int i, int optl, int optr){
if (l>r)
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;
opt=p.second;
dnc(node,l,mid-1,i,optl,opt);
dnc(node,mid+1,r,i,opt,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);
opt=0;
for (int i=0;i<c;i++)
dnc(node,0,c-1,i,opt,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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
172888 KB |
Output is correct |
2 |
Correct |
17 ms |
172892 KB |
Output is correct |
3 |
Correct |
75 ms |
174420 KB |
Output is correct |
4 |
Correct |
18 ms |
172892 KB |
Output is correct |
5 |
Correct |
18 ms |
172892 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4540 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
8548 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
10752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
178264 KB |
Output is correct |
2 |
Correct |
21 ms |
178268 KB |
Output is correct |
3 |
Correct |
22 ms |
178268 KB |
Output is correct |
4 |
Correct |
47 ms |
179028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
124 ms |
10752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
123 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |