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<iostream>
#include<algorithm>
using namespace std;
#define INF 987654321
int i,j,n,d[2229][2229],a[2229][2229];
int main()
{
std::cin.sync_with_stdio(false);
cin>>n;
for(;i++<n;d[i][0]=INF)for(j=0;j++<n;)cin>>a[i][j];
d[0][0]=INF;
for(i=1;i<=n;i++)d[0][i]=INF;
for(j=2;j<=n;j++) {
d[1][j]=min(d[0][j]+(a[1][j]<a[0][j]?0:a[1][j]-a[0][j]+1)
,d[1][j-1]+(a[1][j]<a[1][j-1]?0:a[1][j]-a[1][j-1]+1));
}
for(i=2;i<=n;i++) {
for(j=1;j<=n;j++) {
d[i][j]=min(d[i-1][j]+(a[i][j]<a[i-1][j]?0:a[i][j]-a[i-1][j]+1)
,d[i][j-1]+(a[i][j]<a[i][j-1]?0:a[i][j]-a[i][j-1]+1));
}
}
cout<<d[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... |