#include<stdio.h>
int n, a[2230][2230], dp[2230][2230];
int main()
{
int i, j, x, y;
scanf("%d", &n);
for(i=1; i<=n; ++i)
{
for(j=1; j<=n; ++j)
{
scanf("%d", &a[i][j]);
}
}
for(i=1; i<=n; ++i)
{
for(j=1; j<=n; ++j)
{
if(i==1 && j==1) continue;
x=i>1?dp[i-1][j]:1234567890;
y=j>1?dp[i][j-1]:1234567890;
if(a[i][j]>=a[i-1][j]) x+=a[i][j]-a[i-1][j]+1;
if(a[i][j]>=a[i][j-1]) y+=a[i][j]-a[i][j-1]+1;
if(x<y) dp[i][j]=x;
else dp[i][j]=y;
}
}
printf("%d", dp[n][n]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39936 KB |
Output is correct |
2 |
Correct |
0 ms |
39936 KB |
Output is correct |
3 |
Correct |
0 ms |
39936 KB |
Output is correct |
4 |
Correct |
0 ms |
39936 KB |
Output is correct |
5 |
Correct |
0 ms |
39936 KB |
Output is correct |
6 |
Correct |
0 ms |
39936 KB |
Output is correct |
7 |
Correct |
0 ms |
39936 KB |
Output is correct |
8 |
Correct |
0 ms |
39936 KB |
Output is correct |
9 |
Correct |
0 ms |
39936 KB |
Output is correct |
10 |
Correct |
0 ms |
39936 KB |
Output is correct |
11 |
Correct |
0 ms |
39936 KB |
Output is correct |
12 |
Correct |
0 ms |
39936 KB |
Output is correct |
13 |
Correct |
0 ms |
39936 KB |
Output is correct |
14 |
Correct |
0 ms |
39936 KB |
Output is correct |
15 |
Correct |
0 ms |
39936 KB |
Output is correct |
16 |
Correct |
0 ms |
39936 KB |
Output is correct |
17 |
Correct |
0 ms |
39936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39936 KB |
Output is correct |
2 |
Correct |
0 ms |
39936 KB |
Output is correct |
3 |
Correct |
0 ms |
39936 KB |
Output is correct |
4 |
Correct |
0 ms |
39936 KB |
Output is correct |
5 |
Correct |
0 ms |
39936 KB |
Output is correct |
6 |
Correct |
0 ms |
39936 KB |
Output is correct |
7 |
Correct |
0 ms |
39936 KB |
Output is correct |
8 |
Correct |
0 ms |
39936 KB |
Output is correct |
9 |
Correct |
0 ms |
39936 KB |
Output is correct |
10 |
Correct |
0 ms |
39936 KB |
Output is correct |
11 |
Correct |
0 ms |
39936 KB |
Output is correct |
12 |
Correct |
0 ms |
39936 KB |
Output is correct |
13 |
Correct |
0 ms |
39936 KB |
Output is correct |
14 |
Correct |
0 ms |
39936 KB |
Output is correct |
15 |
Correct |
0 ms |
39936 KB |
Output is correct |
16 |
Correct |
0 ms |
39936 KB |
Output is correct |
17 |
Correct |
0 ms |
39936 KB |
Output is correct |
18 |
Correct |
0 ms |
39936 KB |
Output is correct |
19 |
Correct |
0 ms |
39936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39936 KB |
Output is correct |
2 |
Correct |
4 ms |
39936 KB |
Output is correct |
3 |
Correct |
8 ms |
39936 KB |
Output is correct |
4 |
Correct |
8 ms |
39936 KB |
Output is correct |
5 |
Correct |
4 ms |
39936 KB |
Output is correct |
6 |
Correct |
4 ms |
39936 KB |
Output is correct |
7 |
Correct |
8 ms |
39936 KB |
Output is correct |
8 |
Correct |
8 ms |
39936 KB |
Output is correct |
9 |
Correct |
8 ms |
39936 KB |
Output is correct |
10 |
Correct |
4 ms |
39936 KB |
Output is correct |
11 |
Correct |
4 ms |
39936 KB |
Output is correct |
12 |
Correct |
8 ms |
39936 KB |
Output is correct |
13 |
Correct |
8 ms |
39936 KB |
Output is correct |
14 |
Correct |
4 ms |
39936 KB |
Output is correct |
15 |
Correct |
4 ms |
39936 KB |
Output is correct |
16 |
Correct |
4 ms |
39936 KB |
Output is correct |
17 |
Correct |
8 ms |
39936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
664 ms |
39936 KB |
Output is correct |
2 |
Correct |
664 ms |
39936 KB |
Output is correct |
3 |
Correct |
676 ms |
39936 KB |
Output is correct |
4 |
Correct |
652 ms |
39936 KB |
Output is correct |
5 |
Correct |
560 ms |
39936 KB |
Output is correct |
6 |
Correct |
616 ms |
39936 KB |
Output is correct |
7 |
Correct |
672 ms |
39936 KB |
Output is correct |
8 |
Correct |
668 ms |
39936 KB |
Output is correct |
9 |
Correct |
664 ms |
39936 KB |
Output is correct |
10 |
Correct |
580 ms |
39936 KB |
Output is correct |
11 |
Correct |
568 ms |
39936 KB |
Output is correct |
12 |
Correct |
564 ms |
39936 KB |
Output is correct |
13 |
Correct |
508 ms |
39936 KB |
Output is correct |
14 |
Correct |
572 ms |
39936 KB |
Output is correct |
15 |
Correct |
464 ms |
39936 KB |
Output is correct |
16 |
Correct |
572 ms |
39936 KB |
Output is correct |
17 |
Correct |
572 ms |
39936 KB |
Output is correct |
18 |
Correct |
508 ms |
39936 KB |
Output is correct |
19 |
Correct |
564 ms |
39936 KB |
Output is correct |
20 |
Correct |
588 ms |
39936 KB |
Output is correct |
21 |
Correct |
532 ms |
39936 KB |
Output is correct |