This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int sz=20,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;
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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |