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>
#include <algorithm>
using namespace std;
const int MAX = 2300, INF = 1234567890;
int n, map[MAX][MAX];
void input(){
scanf("%d", &n);
int i, j;
for(i = 1; i<=n; i++){
for(j = 1; j<=n; j++){
scanf("%d", &map[i][j]);
}
}
}
int cost[MAX][MAX];
void solve(){
int i, j;
for(i = 1; i<=n; i++){
for(j = 1; j<=n; j++){
if(i == 1 && j == 1) continue;
cost[i][j] = INF;
if(i > 1) cost[i][j] = min(cost[i][j], cost[i-1][j]+max(0, map[i][j]-map[i-1][j]+1));
if(j > 1) cost[i][j] = min(cost[i][j], cost[i][j-1]+max(0, map[i][j]-map[i][j-1]+1));
}
}
printf("%d\n", cost[n][n]);
}
int main(){
input();
solve();
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... |