#include<stdio.h>
int n,a[2500][2500],d[2500][2500];
int mini(int x,int y)
{
if(x<y) return x;
return y;
}
int f(int x)
{
if(x>0) return x;
return 0;
}
int main()
{
int 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++)
{
for(j=0;j<=n;j++)
{
if(i==0 || j==0) d[i][j]=2100000000;
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==1 && j==1) continue;
d[i][j]=mini(d[i-1][j]+f(a[i][j]-a[i-1][j]+1),d[i][j-1]+f(a[i][j]-a[i][j-1]+1));
}
}
printf("%d",d[n][n]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
49916 KB |
Output is correct |
6 |
Correct |
0 ms |
49916 KB |
Output is correct |
7 |
Correct |
0 ms |
49916 KB |
Output is correct |
8 |
Correct |
0 ms |
49916 KB |
Output is correct |
9 |
Correct |
0 ms |
49916 KB |
Output is correct |
10 |
Correct |
0 ms |
49916 KB |
Output is correct |
11 |
Correct |
0 ms |
49916 KB |
Output is correct |
12 |
Correct |
0 ms |
49916 KB |
Output is correct |
13 |
Correct |
0 ms |
49916 KB |
Output is correct |
14 |
Correct |
0 ms |
49916 KB |
Output is correct |
15 |
Correct |
0 ms |
49916 KB |
Output is correct |
16 |
Correct |
0 ms |
49916 KB |
Output is correct |
17 |
Correct |
0 ms |
49916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
49916 KB |
Output is correct |
6 |
Correct |
0 ms |
49916 KB |
Output is correct |
7 |
Correct |
0 ms |
49916 KB |
Output is correct |
8 |
Correct |
0 ms |
49916 KB |
Output is correct |
9 |
Correct |
0 ms |
49916 KB |
Output is correct |
10 |
Correct |
0 ms |
49916 KB |
Output is correct |
11 |
Correct |
0 ms |
49916 KB |
Output is correct |
12 |
Correct |
0 ms |
49916 KB |
Output is correct |
13 |
Correct |
0 ms |
49916 KB |
Output is correct |
14 |
Correct |
0 ms |
49916 KB |
Output is correct |
15 |
Correct |
0 ms |
49916 KB |
Output is correct |
16 |
Correct |
0 ms |
49916 KB |
Output is correct |
17 |
Correct |
0 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 |
8 ms |
49916 KB |
Output is correct |
2 |
Correct |
8 ms |
49916 KB |
Output is correct |
3 |
Correct |
0 ms |
49916 KB |
Output is correct |
4 |
Correct |
8 ms |
49916 KB |
Output is correct |
5 |
Correct |
8 ms |
49916 KB |
Output is correct |
6 |
Correct |
8 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 |
0 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 |
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 |
4 ms |
49916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
600 ms |
49916 KB |
Output is correct |
2 |
Correct |
596 ms |
49916 KB |
Output is correct |
3 |
Correct |
608 ms |
49916 KB |
Output is correct |
4 |
Correct |
620 ms |
49916 KB |
Output is correct |
5 |
Correct |
512 ms |
49916 KB |
Output is correct |
6 |
Correct |
556 ms |
49916 KB |
Output is correct |
7 |
Correct |
616 ms |
49916 KB |
Output is correct |
8 |
Correct |
612 ms |
49916 KB |
Output is correct |
9 |
Correct |
592 ms |
49916 KB |
Output is correct |
10 |
Correct |
604 ms |
49916 KB |
Output is correct |
11 |
Correct |
548 ms |
49916 KB |
Output is correct |
12 |
Correct |
544 ms |
49916 KB |
Output is correct |
13 |
Correct |
512 ms |
49916 KB |
Output is correct |
14 |
Correct |
540 ms |
49916 KB |
Output is correct |
15 |
Correct |
476 ms |
49916 KB |
Output is correct |
16 |
Correct |
584 ms |
49916 KB |
Output is correct |
17 |
Correct |
592 ms |
49916 KB |
Output is correct |
18 |
Correct |
536 ms |
49916 KB |
Output is correct |
19 |
Correct |
580 ms |
49916 KB |
Output is correct |
20 |
Correct |
576 ms |
49916 KB |
Output is correct |
21 |
Correct |
532 ms |
49916 KB |
Output is correct |