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>
#include<memory.h>
#define INF 987654321
using namespace std;
int n;
int a[2500][2500];
int d[2500][2500];
int f(int x,int y){
if(x>=n||y>=n)return INF;
if(x==n-1&&y==n-1)return 0;
int& ret=d[x][y];
if(ret!=-1)return ret;
ret=min(f(x+1,y)+max(a[x+1][y]-a[x][y]+1,0),f(x,y+1)+max(a[x][y+1]-a[x][y]+1,0));
return ret;
}
int main(){
scanf("%d",&n);
memset(d,-1,sizeof(d));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("%d",f(0,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... |