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>
#include <algorithm>
int N,p; long long A[2][2222],D[2][2222];
int main()
{
scanf ("%d",&N);
for (int i=0;i<N;i++){
for (int j=0;j<N;j++){
scanf ("%lld",&A[p][j]);
if (i == 0 && j == 0) D[p][j] = 0;
else D[p][j] = 1000000000000000ll;
if (i != 0){
int a = (A[!p][j] > A[p][j]) ? 0 : A[p][j] - A[!p][j] + 1;
if (D[p][j] > D[!p][j] + a)
D[p][j] = D[!p][j] + a;
}
if (j != 0){
int a = (A[p][j-1] > A[p][j]) ? 0 : A[p][j] - A[p][j-1] + 1;
if (D[p][j] > D[p][j-1] + a)
D[p][j] = D[p][j-1] + a;
}
}
p = !p;
}
printf ("%d\n",D[!p][N-1]);
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... |