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 <cstring>
#include <algorithm>
using namespace std;
int arr[2222][2222], n;
int dp[2222][2222];
int getAns(int y, int x)
{
int &ret = dp[y][x];
if(ret != -1) return ret;
if(y == n - 1 and x == n - 1) ret = 0;
else
{
ret = (1 << 30);
if(y < n - 1) ret = min(ret, getAns(y + 1, x) + max(0, arr[y + 1][x] + 1 - arr[y][x]));
if(x < n - 1) ret = min(ret, getAns(y, x + 1) + max(0, arr[y][x + 1] + 1 - arr[y][x]));
}
return ret;
}
int main(void)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
scanf("%d", arr[i] + j);
memset(dp, -1, sizeof(dp));
printf("%d\n", getAns(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... |