#include <cstdio>
int map[2300][2300];
int n;
int mincost[2300][2300];
int max(int a,int b) {return (a>b)?a:b; }
int min(int a,int b) {return (a<b)?a:b; }
int main()
{
scanf("%d",&n);
int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&map[i][j]);
if(i==1 && j==1){
mincost[i][j]=0;
} else {
mincost[i][j]=2147483600;
if(j>1) {
if(map[i][j-1]<=map[i][j]){
mincost[i][j]=min(mincost[i][j],
mincost[i][j-1]+map[i][j]-map[i][j-1]+1);
} else {
mincost[i][j]=min(mincost[i][j],
mincost[i][j-1]);
}
}
if(i>1) {
if(map[i-1][j]<=map[i][j]){
mincost[i][j]=min(mincost[i][j],
mincost[i-1][j]+map[i][j]-map[i-1][j]+1);
} else {
mincost[i][j]=min(mincost[i][j],
mincost[i-1][j]);
}
}
}
}
}
printf("%d\n",mincost[n][n]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
42416 KB |
Output is correct |
2 |
Correct |
0 ms |
42416 KB |
Output is correct |
3 |
Correct |
0 ms |
42416 KB |
Output is correct |
4 |
Correct |
0 ms |
42416 KB |
Output is correct |
5 |
Correct |
0 ms |
42416 KB |
Output is correct |
6 |
Correct |
0 ms |
42416 KB |
Output is correct |
7 |
Correct |
0 ms |
42416 KB |
Output is correct |
8 |
Correct |
0 ms |
42416 KB |
Output is correct |
9 |
Correct |
0 ms |
42416 KB |
Output is correct |
10 |
Correct |
0 ms |
42416 KB |
Output is correct |
11 |
Correct |
0 ms |
42416 KB |
Output is correct |
12 |
Correct |
0 ms |
42416 KB |
Output is correct |
13 |
Correct |
0 ms |
42416 KB |
Output is correct |
14 |
Correct |
0 ms |
42416 KB |
Output is correct |
15 |
Correct |
0 ms |
42416 KB |
Output is correct |
16 |
Correct |
0 ms |
42416 KB |
Output is correct |
17 |
Correct |
0 ms |
42416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
42416 KB |
Output is correct |
2 |
Correct |
0 ms |
42416 KB |
Output is correct |
3 |
Correct |
0 ms |
42416 KB |
Output is correct |
4 |
Correct |
0 ms |
42416 KB |
Output is correct |
5 |
Correct |
0 ms |
42416 KB |
Output is correct |
6 |
Correct |
0 ms |
42416 KB |
Output is correct |
7 |
Correct |
0 ms |
42416 KB |
Output is correct |
8 |
Correct |
0 ms |
42416 KB |
Output is correct |
9 |
Correct |
0 ms |
42416 KB |
Output is correct |
10 |
Correct |
0 ms |
42416 KB |
Output is correct |
11 |
Correct |
0 ms |
42416 KB |
Output is correct |
12 |
Correct |
0 ms |
42416 KB |
Output is correct |
13 |
Correct |
0 ms |
42416 KB |
Output is correct |
14 |
Correct |
0 ms |
42416 KB |
Output is correct |
15 |
Correct |
0 ms |
42416 KB |
Output is correct |
16 |
Correct |
0 ms |
42416 KB |
Output is correct |
17 |
Correct |
0 ms |
42416 KB |
Output is correct |
18 |
Correct |
0 ms |
42416 KB |
Output is correct |
19 |
Correct |
0 ms |
42416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
42416 KB |
Output is correct |
2 |
Correct |
8 ms |
42416 KB |
Output is correct |
3 |
Correct |
8 ms |
42416 KB |
Output is correct |
4 |
Correct |
4 ms |
42416 KB |
Output is correct |
5 |
Correct |
8 ms |
42416 KB |
Output is correct |
6 |
Correct |
8 ms |
42416 KB |
Output is correct |
7 |
Correct |
8 ms |
42416 KB |
Output is correct |
8 |
Correct |
8 ms |
42416 KB |
Output is correct |
9 |
Correct |
8 ms |
42416 KB |
Output is correct |
10 |
Correct |
8 ms |
42416 KB |
Output is correct |
11 |
Correct |
4 ms |
42416 KB |
Output is correct |
12 |
Correct |
8 ms |
42416 KB |
Output is correct |
13 |
Correct |
8 ms |
42416 KB |
Output is correct |
14 |
Correct |
8 ms |
42416 KB |
Output is correct |
15 |
Correct |
8 ms |
42416 KB |
Output is correct |
16 |
Correct |
4 ms |
42416 KB |
Output is correct |
17 |
Correct |
4 ms |
42416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
648 ms |
42416 KB |
Output is correct |
2 |
Correct |
656 ms |
42416 KB |
Output is correct |
3 |
Correct |
640 ms |
42416 KB |
Output is correct |
4 |
Correct |
636 ms |
42416 KB |
Output is correct |
5 |
Correct |
512 ms |
42416 KB |
Output is correct |
6 |
Correct |
592 ms |
42416 KB |
Output is correct |
7 |
Correct |
648 ms |
42416 KB |
Output is correct |
8 |
Correct |
636 ms |
42416 KB |
Output is correct |
9 |
Correct |
636 ms |
42416 KB |
Output is correct |
10 |
Correct |
596 ms |
42416 KB |
Output is correct |
11 |
Correct |
572 ms |
42416 KB |
Output is correct |
12 |
Correct |
588 ms |
42416 KB |
Output is correct |
13 |
Correct |
516 ms |
42416 KB |
Output is correct |
14 |
Correct |
564 ms |
42416 KB |
Output is correct |
15 |
Correct |
464 ms |
42416 KB |
Output is correct |
16 |
Correct |
580 ms |
42416 KB |
Output is correct |
17 |
Correct |
600 ms |
42416 KB |
Output is correct |
18 |
Correct |
536 ms |
42416 KB |
Output is correct |
19 |
Correct |
600 ms |
42416 KB |
Output is correct |
20 |
Correct |
588 ms |
42416 KB |
Output is correct |
21 |
Correct |
532 ms |
42416 KB |
Output is correct |