#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int a[2500][2500],n;
int dp[2500][2500];
int main(){
memset(a,0x3f,sizeof(a));
scanf("%d",&n);
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
scanf("%d",&a[i][j]);
}
}
for(int j=2; j<=n; j++){
dp[1][j] = dp[1][j-1] + max(a[1][j]-a[1][j-1]+1,0);
}
for(int i=2; i<=n; i++){
dp[i][1] = dp[i-1][1] + max(a[i][1]-a[i-1][1]+1,0);
for(int j=2; j<=n; j++){
dp[i][j] = min(dp[i-1][j] + max(a[i][j] - a[i-1][j]+1,0),dp[i][j-1] + max(a[i][j] - a[i][j-1]+1,0));
}
}
printf("%d",dp[n][n]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
49916 KB |
Output is correct |
2 |
Correct |
0 ms |
49916 KB |
Output is correct |
3 |
Correct |
0 ms |
49916 KB |
Output is correct |
4 |
Correct |
0 ms |
49916 KB |
Output is correct |
5 |
Correct |
4 ms |
49916 KB |
Output is correct |
6 |
Correct |
4 ms |
49916 KB |
Output is correct |
7 |
Correct |
8 ms |
49916 KB |
Output is correct |
8 |
Correct |
4 ms |
49916 KB |
Output is correct |
9 |
Correct |
8 ms |
49916 KB |
Output is correct |
10 |
Correct |
0 ms |
49916 KB |
Output is correct |
11 |
Correct |
8 ms |
49916 KB |
Output is correct |
12 |
Correct |
8 ms |
49916 KB |
Output is correct |
13 |
Correct |
0 ms |
49916 KB |
Output is correct |
14 |
Correct |
4 ms |
49916 KB |
Output is correct |
15 |
Correct |
8 ms |
49916 KB |
Output is correct |
16 |
Correct |
4 ms |
49916 KB |
Output is correct |
17 |
Correct |
0 ms |
49916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
49916 KB |
Output is correct |
2 |
Correct |
8 ms |
49916 KB |
Output is correct |
3 |
Correct |
8 ms |
49916 KB |
Output is correct |
4 |
Correct |
12 ms |
49916 KB |
Output is correct |
5 |
Correct |
0 ms |
49916 KB |
Output is correct |
6 |
Correct |
0 ms |
49916 KB |
Output is correct |
7 |
Correct |
4 ms |
49916 KB |
Output is correct |
8 |
Correct |
4 ms |
49916 KB |
Output is correct |
9 |
Correct |
8 ms |
49916 KB |
Output is correct |
10 |
Correct |
8 ms |
49916 KB |
Output is correct |
11 |
Correct |
8 ms |
49916 KB |
Output is correct |
12 |
Correct |
4 ms |
49916 KB |
Output is correct |
13 |
Correct |
4 ms |
49916 KB |
Output is correct |
14 |
Correct |
4 ms |
49916 KB |
Output is correct |
15 |
Correct |
4 ms |
49916 KB |
Output is correct |
16 |
Correct |
0 ms |
49916 KB |
Output is correct |
17 |
Correct |
8 ms |
49916 KB |
Output is correct |
18 |
Correct |
0 ms |
49916 KB |
Output is correct |
19 |
Correct |
0 ms |
49916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
49916 KB |
Output is correct |
2 |
Correct |
4 ms |
49916 KB |
Output is correct |
3 |
Correct |
8 ms |
49916 KB |
Output is correct |
4 |
Correct |
20 ms |
49916 KB |
Output is correct |
5 |
Correct |
4 ms |
49916 KB |
Output is correct |
6 |
Correct |
16 ms |
49916 KB |
Output is correct |
7 |
Correct |
12 ms |
49916 KB |
Output is correct |
8 |
Correct |
16 ms |
49916 KB |
Output is correct |
9 |
Correct |
20 ms |
49916 KB |
Output is correct |
10 |
Correct |
16 ms |
49916 KB |
Output is correct |
11 |
Correct |
8 ms |
49916 KB |
Output is correct |
12 |
Correct |
12 ms |
49916 KB |
Output is correct |
13 |
Correct |
8 ms |
49916 KB |
Output is correct |
14 |
Correct |
12 ms |
49916 KB |
Output is correct |
15 |
Correct |
16 ms |
49916 KB |
Output is correct |
16 |
Correct |
8 ms |
49916 KB |
Output is correct |
17 |
Correct |
12 ms |
49916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
49916 KB |
Output is correct |
2 |
Correct |
588 ms |
49916 KB |
Output is correct |
3 |
Correct |
576 ms |
49916 KB |
Output is correct |
4 |
Correct |
568 ms |
49916 KB |
Output is correct |
5 |
Correct |
480 ms |
49916 KB |
Output is correct |
6 |
Correct |
520 ms |
49916 KB |
Output is correct |
7 |
Correct |
596 ms |
49916 KB |
Output is correct |
8 |
Correct |
568 ms |
49916 KB |
Output is correct |
9 |
Correct |
576 ms |
49916 KB |
Output is correct |
10 |
Correct |
544 ms |
49916 KB |
Output is correct |
11 |
Correct |
556 ms |
49916 KB |
Output is correct |
12 |
Correct |
540 ms |
49916 KB |
Output is correct |
13 |
Correct |
476 ms |
49916 KB |
Output is correct |
14 |
Correct |
540 ms |
49916 KB |
Output is correct |
15 |
Correct |
464 ms |
49916 KB |
Output is correct |
16 |
Correct |
568 ms |
49916 KB |
Output is correct |
17 |
Correct |
552 ms |
49916 KB |
Output is correct |
18 |
Correct |
516 ms |
49916 KB |
Output is correct |
19 |
Correct |
556 ms |
49916 KB |
Output is correct |
20 |
Correct |
572 ms |
49916 KB |
Output is correct |
21 |
Correct |
524 ms |
49916 KB |
Output is correct |