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[2230][2230], dp[2230][2230];
int main()
{
int i, j, x, y;
scanf("%d", &n);
for(i=1; i<=n; ++i)
{
for(j=1; j<=n; ++j)
{
scanf("%d", &a[i][j]);
}
}
for(i=1; i<=n; ++i)
{
for(j=1; j<=n; ++j)
{
if(i==1 && j==1) continue;
x=i>1?dp[i-1][j]:1234567890;
y=j>1?dp[i][j-1]:1234567890;
if(a[i][j]>=a[i-1][j]) x+=a[i][j]-a[i-1][j]+1;
if(a[i][j]>=a[i][j-1]) y+=a[i][j]-a[i][j-1]+1;
if(x<y) dp[i][j]=x;
else dp[i][j]=y;
}
}
printf("%d", dp[n][n]);
}
# | 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... |