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"
#define SZ 256
#define INF 999999999
int D[512][201][201],bucket_sz,h[5010][210],v[5010][210],TP[23][210][210],r,c;
void Do(int num,int a)
{
int i,j,k,bsz=bucket_sz;
if(a+bsz>r)bsz=r-a;
for(i=0;i<=bsz;i++)
for(j=0;j<c;j++)
for(k=0;k<c;k++)
TP[i][j][k]=INF;
for(i=0;i<c;i++)TP[0][i][i]=0;
for(i=0;i<bsz;i++)
{
for(j=0;j<c;j++){
for(k=1;k<c;k++)
if(TP[i][j][k]>TP[i][j][k-1]+h[a+i][k-1])
TP[i][j][k]=TP[i][j][k-1]+h[a+i][k-1];
for(k=c-2;k>=0;k--)
if(TP[i][j][k]>TP[i][j][k+1]+h[a+i][k])
TP[i][j][k]=TP[i][j][k+1]+h[a+i][k];
}
for(j=0;j<c;j++)
for(k=0;k<c;k++)
TP[i+1][j][k]=TP[i][j][k]+v[a+i][k];
}
for(i=0;i<c;i++)
for(j=0;j<c;j++)
D[num][i][j]=TP[bsz][i][j];
}
void Update(int a)
{
int i,j,k,b,e,w[201],s,l;
int c1=a*2,c2=a*2+1;
for(i=0;i<c;i++)for(j=0;j<c;j++)D[a][i][j]=INF+1;
for(i=0;i<c;i++)w[i]=0;
w[0]=c-1;
for(i=c-1;i>-c;i--){
b=-i;e=c-1-i;
if(b<0)b=0;
if(e>=c)e=c-1;
for(j=b;j<=e;j++){
if(j==b)s=0;
else s=w[j-1];
if(j==e)l=c-1;
else l=w[j];
for(k=s;k<=l;k++){
if(D[a][j][j+i]>D[c1][j][k]+D[c2][k][j+i]){
D[a][j][j+i]=D[c1][j][k]+D[c2][k][j+i];
w[j]=k;
}
}
}
}
}
void changeV(int P, int Q, int W)
{
v[P][Q]=W;
int a=P/bucket_sz;
Do(SZ+a,a*bucket_sz);
a+=SZ;
while(a>1){
a>>=1;
Update(a);
}
}
void changeH(int P, int Q, int W)
{
h[P][Q]=W;
int a=P/bucket_sz;
Do(SZ+a,a*bucket_sz);
a+=SZ;
while(a>1){
a>>=1;
Update(a);
}
}
int escape(int V1, int V2)
{
return D[1][V1][V2];
}
void init(int R, int C, int H[5000][200], int V[5000][200])
{
r=R,c=C;
int i,j,k;
for(i=0;i<R;i++)for(j=0;j<C-1;j++)h[i][j]=H[i][j];
for(i=0;i<R-1;i++)for(j=0;j<C;j++)v[i][j]=V[i][j];
bucket_sz=(R-1)/256+1;
for(i=0;i<R;i+=bucket_sz)
{
Do(SZ+i/bucket_sz,i);
}
for(i=SZ+i/bucket_sz;i<512;i++){
for(j=0;j<C;j++){
for(k=0;k<C;k++)D[i][j][k]=INF;
D[i][j][j]=0;
}
}
for(i=SZ-1;i>=1;i--)Update(i);
}
# | 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... |