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 arr[2222][2222];
int mem[2222][2222];
inline int mx(int a,int b)
{
return a>b?a:b;
}
inline int mn(int a,int b)
{
return a<b?a:b;
}
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&arr[i][j]);
for(i=n-2;i>=0;i--)
{
mem[i][n-1]=mx(arr[i+1][n-1]-arr[i][n-1]+1,0)+mem[i+1][n-1];
mem[n-1][i]=mx(arr[n-1][i+1]-arr[n-1][i]+1,0)+mem[n-1][i+1];
}
for(i=n-2;i>=0;i--)
for(j=n-2;j>=0;j--)
mem[i][j]=mn(mx(arr[i+1][j]-arr[i][j]+1,0)+mem[i+1][j],mx(arr[i][j+1]-arr[i][j]+1,0)+mem[i][j+1]);
printf("%d",mem[0][0]);
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... |