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 MAXN 2224
int N,A[MAXN][MAXN],D[MAXN][MAXN];
int main()
{
int i,j,k,s;
scanf("%d",&N);
for (i=1;i<=N;i++) for (j=1;j<=N;j++) scanf("%d",A[i]+j), D[i][j] = 2e9;
D[1][1] = 0;
for (i=1;i<=N;i++) for (j=1;j<=N;j++){
if (i < N){
int v = A[i][j] <= A[i+1][j] ? A[i+1][j]-A[i][j]+1 : 0;
if (D[i+1][j] > D[i][j]+v) D[i+1][j] = D[i][j]+v;
}
if (j < N){
int v = A[i][j] <= A[i][j+1] ? A[i][j+1]-A[i][j]+1 : 0;
if (D[i][j+1] > D[i][j]+v) D[i][j+1] = D[i][j]+v;
}
}
printf("%d\n",D[N][N]);
}
# | 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... |