#include<stdio.h>
#define INF 2100000000
int n, m[2225][2225];
int dp[2225][2225];
int min(int a, int b)
{
if(a<=b) return a;
if(a>b) return b;
}
int p(int a, int b)
{
if(a-b>0) return 0;
if(a-b<=0) return b-a+1;
}
int main()
{
int i, j;
scanf("%d",&n);
for(i=1 ; i<=n ; i++)
{
for(j=1 ; j<=n ; j++)
{
scanf("%d",&m[i][j]);
dp[i][j]=INF;
}
}
dp[1][1]=0;
for(i=2 ; i<=n ; i++) dp[i][1]=dp[i-1][1]+p(m[i-1][1],m[i][1]), dp[1][i]=dp[1][i-1]+p(m[1][i-1],m[1][i]);
for(i=2 ; i<=n ; i++) for(j=2 ; j<=n ; j++) dp[i][j]=min(dp[i-1][j]+p(m[i-1][j],m[i][j]),dp[i][j-1]+p(m[i][j-1],m[i][j]));
printf("%d",dp[n][n]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39764 KB |
Output is correct |
2 |
Correct |
0 ms |
39764 KB |
Output is correct |
3 |
Correct |
0 ms |
39764 KB |
Output is correct |
4 |
Correct |
0 ms |
39764 KB |
Output is correct |
5 |
Correct |
0 ms |
39764 KB |
Output is correct |
6 |
Correct |
0 ms |
39764 KB |
Output is correct |
7 |
Correct |
0 ms |
39764 KB |
Output is correct |
8 |
Correct |
0 ms |
39764 KB |
Output is correct |
9 |
Correct |
0 ms |
39764 KB |
Output is correct |
10 |
Correct |
0 ms |
39764 KB |
Output is correct |
11 |
Correct |
0 ms |
39764 KB |
Output is correct |
12 |
Correct |
0 ms |
39764 KB |
Output is correct |
13 |
Correct |
0 ms |
39764 KB |
Output is correct |
14 |
Correct |
0 ms |
39764 KB |
Output is correct |
15 |
Correct |
0 ms |
39764 KB |
Output is correct |
16 |
Correct |
0 ms |
39764 KB |
Output is correct |
17 |
Correct |
0 ms |
39764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39764 KB |
Output is correct |
2 |
Correct |
0 ms |
39764 KB |
Output is correct |
3 |
Correct |
0 ms |
39764 KB |
Output is correct |
4 |
Correct |
0 ms |
39764 KB |
Output is correct |
5 |
Correct |
0 ms |
39764 KB |
Output is correct |
6 |
Correct |
0 ms |
39764 KB |
Output is correct |
7 |
Correct |
0 ms |
39764 KB |
Output is correct |
8 |
Correct |
0 ms |
39764 KB |
Output is correct |
9 |
Correct |
0 ms |
39764 KB |
Output is correct |
10 |
Correct |
0 ms |
39764 KB |
Output is correct |
11 |
Correct |
0 ms |
39764 KB |
Output is correct |
12 |
Correct |
0 ms |
39764 KB |
Output is correct |
13 |
Correct |
0 ms |
39764 KB |
Output is correct |
14 |
Correct |
0 ms |
39764 KB |
Output is correct |
15 |
Correct |
0 ms |
39764 KB |
Output is correct |
16 |
Correct |
0 ms |
39764 KB |
Output is correct |
17 |
Correct |
0 ms |
39764 KB |
Output is correct |
18 |
Correct |
0 ms |
39764 KB |
Output is correct |
19 |
Correct |
0 ms |
39764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
39764 KB |
Output is correct |
2 |
Correct |
4 ms |
39764 KB |
Output is correct |
3 |
Correct |
8 ms |
39764 KB |
Output is correct |
4 |
Correct |
8 ms |
39764 KB |
Output is correct |
5 |
Correct |
0 ms |
39764 KB |
Output is correct |
6 |
Correct |
8 ms |
39764 KB |
Output is correct |
7 |
Correct |
8 ms |
39764 KB |
Output is correct |
8 |
Correct |
8 ms |
39764 KB |
Output is correct |
9 |
Correct |
4 ms |
39764 KB |
Output is correct |
10 |
Correct |
4 ms |
39764 KB |
Output is correct |
11 |
Correct |
4 ms |
39764 KB |
Output is correct |
12 |
Correct |
8 ms |
39764 KB |
Output is correct |
13 |
Correct |
4 ms |
39764 KB |
Output is correct |
14 |
Correct |
8 ms |
39764 KB |
Output is correct |
15 |
Correct |
8 ms |
39764 KB |
Output is correct |
16 |
Correct |
8 ms |
39764 KB |
Output is correct |
17 |
Correct |
8 ms |
39764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
616 ms |
39764 KB |
Output is correct |
2 |
Correct |
624 ms |
39764 KB |
Output is correct |
3 |
Correct |
620 ms |
39764 KB |
Output is correct |
4 |
Correct |
608 ms |
39764 KB |
Output is correct |
5 |
Correct |
536 ms |
39764 KB |
Output is correct |
6 |
Correct |
576 ms |
39764 KB |
Output is correct |
7 |
Correct |
636 ms |
39764 KB |
Output is correct |
8 |
Correct |
628 ms |
39764 KB |
Output is correct |
9 |
Correct |
616 ms |
39764 KB |
Output is correct |
10 |
Correct |
572 ms |
39764 KB |
Output is correct |
11 |
Correct |
540 ms |
39764 KB |
Output is correct |
12 |
Correct |
524 ms |
39764 KB |
Output is correct |
13 |
Correct |
484 ms |
39764 KB |
Output is correct |
14 |
Correct |
560 ms |
39764 KB |
Output is correct |
15 |
Correct |
464 ms |
39764 KB |
Output is correct |
16 |
Correct |
548 ms |
39764 KB |
Output is correct |
17 |
Correct |
544 ms |
39764 KB |
Output is correct |
18 |
Correct |
504 ms |
39764 KB |
Output is correct |
19 |
Correct |
536 ms |
39764 KB |
Output is correct |
20 |
Correct |
556 ms |
39764 KB |
Output is correct |
21 |
Correct |
500 ms |
39764 KB |
Output is correct |