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>
int n, A[2224][2224] = { 0 }, cost[2224][2224] = { 0 };
int main(){
scanf("%d", &n);
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= n; ++j){
scanf("%d", &A[i][j]);
}
}
for (int i = n; i; --i){
for (int j = n; j; --j){
int rcost = cost[i][j + 1] + (A[i][j] > A[i][j + 1] ? 0 : A[i][j + 1] - A[i][j] + 1);
int dcost = cost[i + 1][j] + (A[i][j] > A[i + 1][j] ? 0 : A[i + 1][j] - A[i][j] + 1);
if (i == n && j == n) cost[n][n] = 0;
else if (i == n) cost[n][j] = rcost;
else if (j == n) cost[i][n] = dcost;
else cost[i][j] = (rcost > dcost ? dcost : rcost);
}
}
printf("%d\n", cost[1][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... |