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<stdio.h>
#define INF 2100000000
int n, m[2225][2225];
int dp[2225][2225];
int min(int a, int b)
{
if(a<=b) return a;
if(a>b) return b;
}
int p(int a, int b)
{
if(a-b>0) return 0;
if(a-b<=0) return b-a+1;
}
int main()
{
int i, j;
scanf("%d",&n);
for(i=1 ; i<=n ; i++)
{
for(j=1 ; j<=n ; j++)
{
scanf("%d",&m[i][j]);
dp[i][j]=INF;
}
}
dp[1][1]=0;
for(i=2 ; i<=n ; i++) dp[i][1]=dp[i-1][1]+p(m[i-1][1],m[i][1]), dp[1][i]=dp[1][i-1]+p(m[1][i-1],m[1][i]);
for(i=2 ; i<=n ; i++) for(j=2 ; j<=n ; j++) dp[i][j]=min(dp[i-1][j]+p(m[i-1][j],m[i][j]),dp[i][j-1]+p(m[i][j-1],m[i][j]));
printf("%d",dp[n][n]);
return 0;
}
# | 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... |