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;
int D[2500][2500], T[2500][2500];
int fn(int x){return x<0? 0:x;}
int min(int a,int b){return a<b? a:b;}
int input(){
scanf("%d",&N);
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
scanf("%d",&T[i][j]);
}
}
for(int i=0;i<2500;i++)for(int j=0;j<2500;j++)D[i][j]=0x6fffffff;
return 0;
}
int solve(){
for(int i=1;i<=N;i++) for(int j=1;j<=N;j++){
if(i==1&&j==1){
D[i][j]=0;
continue;
}
D[i][j]=min(D[i-1][j]+fn(T[i][j]-T[i-1][j]+1),D[i][j-1]+fn(T[i][j]-T[i][j-1]+1));
}
return 0;
}
int output(){
printf("%d",D[N][N]);
return 0;
}
int main(){
input();
solve();
output();
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... |