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>
int map[2300][2300];
int n;
int mincost[2300][2300];
int max(int a,int b) {return (a>b)?a:b; }
int min(int a,int b) {return (a<b)?a:b; }
int main()
{
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&map[i][j]);
if(i==1 && j==1){
mincost[i][j]=0;
} else {
mincost[i][j]=2147483600;
if(j>1) {
if(map[i][j-1]<=map[i][j]){
mincost[i][j]=min(mincost[i][j],
mincost[i][j-1]+map[i][j]-map[i][j-1]+1);
} else {
mincost[i][j]=min(mincost[i][j],
mincost[i][j-1]);
}
}
if(i>1) {
if(map[i-1][j]<=map[i][j]){
mincost[i][j]=min(mincost[i][j],
mincost[i-1][j]+map[i][j]-map[i-1][j]+1);
} else {
mincost[i][j]=min(mincost[i][j],
mincost[i-1][j]);
}
}
}
}
}
printf("%d\n",mincost[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... |