#include<stdio.h>
#include<algorithm>
int a[2225][2225], d[2225][2225];
int main(){
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",a[i]+j);
for(i=0;i<=n;i++)d[i][0] = d[0][i] = 22222;
for(i=1;i<=n;i++)for(j=1;j<=n;j++){
if(i+j==2)continue;
d[i][j] = std::min(d[i-1][j] + ((a[i-1][j]>a[i][j]) ? 0 : a[i][j]-a[i-1][j]+1), d[i][j-1] + ((a[i][j-1]>a[i][j]) ? 0 : a[i][j]-a[i][j-1]+1));
}
printf("%d",d[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 |
4 ms |
39764 KB |
Output is correct |
2 |
Correct |
8 ms |
39764 KB |
Output is correct |
3 |
Correct |
0 ms |
39764 KB |
Output is correct |
4 |
Correct |
8 ms |
39764 KB |
Output is correct |
5 |
Correct |
8 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 |
Incorrect |
8 ms |
39764 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
648 ms |
39764 KB |
Output is correct |
2 |
Correct |
644 ms |
39764 KB |
Output is correct |
3 |
Correct |
640 ms |
39764 KB |
Output is correct |
4 |
Correct |
656 ms |
39764 KB |
Output is correct |
5 |
Correct |
548 ms |
39764 KB |
Output is correct |
6 |
Correct |
600 ms |
39764 KB |
Output is correct |
7 |
Correct |
636 ms |
39764 KB |
Output is correct |
8 |
Correct |
616 ms |
39764 KB |
Output is correct |
9 |
Correct |
628 ms |
39764 KB |
Output is correct |
10 |
Incorrect |
572 ms |
39764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |