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<cstdio>
int a,i,j,x,y,z[2223][2223],D[2223][2223];
int min(int A,int B)
{
if(A>B)return B;
else return A;
}
main()
{
scanf("%d",&a);
for(i=1;i<=a;i++)
{
for(j=1;j<=a;j++)
{
scanf("%d",&z[i][j]);
}
}
for(i=2;i<=a;i++)
{
if(z[i][1]>=z[i-1][1])
{
D[i][1]=D[i-1][1]+z[i][1]-z[i-1][1]+1;
}
else
{
D[i][1]=D[i-1][1];
}
if(z[1][i]>=z[1][i-1])
{
D[1][i]=D[1][i-1]+z[1][i]-z[1][i-1]+1;
}
else
{
D[1][i]=D[1][i-1];
}
}
for(i=2;i<=a;i++)
{
for(j=2;j<=a;j++)
{
if(z[i][j]>=z[i][j-1])
{
x=z[i][j]-z[i][j-1]+1;
}
else x=0;
if(z[i][j]>=z[i-1][j])
{
y=z[i][j]-z[i-1][j]+1;
}
else y=0;
D[i][j]=min(D[i][j-1]+x,D[i-1][j]+y);
}
}
printf("%d",D[a][a]);
}
# | 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... |