#include <stdio.h>
int N, A[2223][2223], D[2223][2223];
void input(void)
{
int i, j;
scanf("%d",&N);
for(i=1 ; i<=N ; i++)
for(j=1 ; j<=N ; j++)
scanf("%d",&A[i][j]);
}
int Dist(int X, int Y)
{
if(X>Y)
return 0;
return Y-X+1;
}
int MIN(int X, int Y)
{
if(X<Y)
return X;
return Y;
}
void process(void)
{
int i, j;
D[1][1]=0;
for(i=2 ; i<=N ; i++)
{
D[1][i]=D[1][i-1]+Dist(A[1][i-1],A[1][i]);
D[i][1]=D[i-1][1]+Dist(A[i-1][1],A[i][1]);
}
for(i=2 ; i<=N ; i++)
for(j=2 ; j<=N ; j++)
D[i][j]=MIN(D[i][j-1]+Dist(A[i][j-1],A[i][j]),D[i-1][j]+Dist(A[i-1][j],A[i][j]));
}
void output(void)
{
printf("%d",D[N][N]);
}
int main(void)
{
input();
process();
output();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39696 KB |
Output is correct |
2 |
Correct |
0 ms |
39696 KB |
Output is correct |
3 |
Correct |
0 ms |
39696 KB |
Output is correct |
4 |
Correct |
0 ms |
39696 KB |
Output is correct |
5 |
Correct |
0 ms |
39696 KB |
Output is correct |
6 |
Correct |
0 ms |
39696 KB |
Output is correct |
7 |
Correct |
0 ms |
39696 KB |
Output is correct |
8 |
Correct |
0 ms |
39696 KB |
Output is correct |
9 |
Correct |
0 ms |
39696 KB |
Output is correct |
10 |
Correct |
0 ms |
39696 KB |
Output is correct |
11 |
Correct |
0 ms |
39696 KB |
Output is correct |
12 |
Correct |
0 ms |
39696 KB |
Output is correct |
13 |
Correct |
0 ms |
39696 KB |
Output is correct |
14 |
Correct |
0 ms |
39696 KB |
Output is correct |
15 |
Correct |
0 ms |
39696 KB |
Output is correct |
16 |
Correct |
0 ms |
39696 KB |
Output is correct |
17 |
Correct |
0 ms |
39696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
39696 KB |
Output is correct |
2 |
Correct |
0 ms |
39696 KB |
Output is correct |
3 |
Correct |
0 ms |
39696 KB |
Output is correct |
4 |
Correct |
0 ms |
39696 KB |
Output is correct |
5 |
Correct |
0 ms |
39696 KB |
Output is correct |
6 |
Correct |
0 ms |
39696 KB |
Output is correct |
7 |
Correct |
0 ms |
39696 KB |
Output is correct |
8 |
Correct |
0 ms |
39696 KB |
Output is correct |
9 |
Correct |
0 ms |
39696 KB |
Output is correct |
10 |
Correct |
0 ms |
39696 KB |
Output is correct |
11 |
Correct |
0 ms |
39696 KB |
Output is correct |
12 |
Correct |
0 ms |
39696 KB |
Output is correct |
13 |
Correct |
0 ms |
39696 KB |
Output is correct |
14 |
Correct |
0 ms |
39696 KB |
Output is correct |
15 |
Correct |
0 ms |
39696 KB |
Output is correct |
16 |
Correct |
0 ms |
39696 KB |
Output is correct |
17 |
Correct |
0 ms |
39696 KB |
Output is correct |
18 |
Correct |
0 ms |
39696 KB |
Output is correct |
19 |
Correct |
0 ms |
39696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
39696 KB |
Output is correct |
2 |
Correct |
0 ms |
39696 KB |
Output is correct |
3 |
Correct |
8 ms |
39696 KB |
Output is correct |
4 |
Correct |
8 ms |
39696 KB |
Output is correct |
5 |
Correct |
8 ms |
39696 KB |
Output is correct |
6 |
Correct |
8 ms |
39696 KB |
Output is correct |
7 |
Correct |
8 ms |
39696 KB |
Output is correct |
8 |
Correct |
8 ms |
39696 KB |
Output is correct |
9 |
Correct |
4 ms |
39696 KB |
Output is correct |
10 |
Correct |
8 ms |
39696 KB |
Output is correct |
11 |
Correct |
4 ms |
39696 KB |
Output is correct |
12 |
Correct |
8 ms |
39696 KB |
Output is correct |
13 |
Correct |
8 ms |
39696 KB |
Output is correct |
14 |
Correct |
4 ms |
39696 KB |
Output is correct |
15 |
Correct |
8 ms |
39696 KB |
Output is correct |
16 |
Correct |
8 ms |
39696 KB |
Output is correct |
17 |
Correct |
8 ms |
39696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
640 ms |
39696 KB |
Output is correct |
2 |
Correct |
636 ms |
39696 KB |
Output is correct |
3 |
Correct |
636 ms |
39696 KB |
Output is correct |
4 |
Correct |
644 ms |
39696 KB |
Output is correct |
5 |
Correct |
552 ms |
39696 KB |
Output is correct |
6 |
Correct |
600 ms |
39696 KB |
Output is correct |
7 |
Correct |
644 ms |
39696 KB |
Output is correct |
8 |
Correct |
636 ms |
39696 KB |
Output is correct |
9 |
Correct |
652 ms |
39696 KB |
Output is correct |
10 |
Correct |
588 ms |
39696 KB |
Output is correct |
11 |
Correct |
568 ms |
39696 KB |
Output is correct |
12 |
Correct |
540 ms |
39696 KB |
Output is correct |
13 |
Correct |
492 ms |
39696 KB |
Output is correct |
14 |
Correct |
528 ms |
39696 KB |
Output is correct |
15 |
Correct |
468 ms |
39696 KB |
Output is correct |
16 |
Correct |
568 ms |
39696 KB |
Output is correct |
17 |
Correct |
592 ms |
39696 KB |
Output is correct |
18 |
Correct |
528 ms |
39696 KB |
Output is correct |
19 |
Correct |
592 ms |
39696 KB |
Output is correct |
20 |
Correct |
548 ms |
39696 KB |
Output is correct |
21 |
Correct |
532 ms |
39696 KB |
Output is correct |