이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |