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>
#define inf 2100000000
using namespace std;
int bae[2222][2222];
int dp[2222][2222];
int n;
int main(){
int i,j;
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
dp[i][j]=inf;
scanf("%d",&bae[i][j]);
}
}
dp[0][0]=0;
for(i=0;i<n-1;i++){
for(j=0;j<n-1;j++){
if(bae[i][j]>bae[i][j+1]){
dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
}else{
dp[i][j+1]=min(dp[i][j+1],bae[i][j+1]-bae[i][j]+1+dp[i][j]);
}
}
for(j=0;j<n;j++){
if(bae[i][j]>bae[i+1][j]){
dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
}else{
dp[i+1][j]=min(dp[i+1][j],bae[i+1][j]-bae[i][j]+1+dp[i][j]);
}
}
}
for(j=0;j<n-1;j++){
if(bae[i][j]>bae[i][j+1]){
dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
}else{
dp[i][j+1]=min(dp[i][j+1],bae[i][j+1]-bae[i][j]+1+dp[i][j]);
}
}
printf("%d",dp[n-1][n-1]);
}
# | 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... |