#include<cstdio>
#include<algorithm>
int a[2222][2222];
int main()
{
int i,j,n,r=0;
scanf("%d",&n);
for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]);
if(n==2)
{
printf("%d",std::min(std::max(a[0][1]-a[0][0]+1,0)+std::max(a[1][1]-a[0][1]+1,0),std::max(a[1][0]-a[0][0]+1,0)+std::max(a[1][1]-a[1][0]+1,0)));
return 0;
}
i=j=0;
while(i!=n-1||j!=n-1)
{
if(i==n-1)
{
r+=std::max(a[i][j+1]-a[i][j]+1,0);
j++;
}
else if(j==n-1)
{
r+=std::max(a[i+1][j]-a[i][j]+1,0);
i++;
}
else
{
if(std::max(a[i][j+1]-a[i][j]+1,0)<std::max(a[i+1][j]-a[i][j]+1,0))
{
r+=std::max(a[i][j+1]-a[i][j]+1,0);
j++;
}
else if(std::max(a[i][j+1]-a[i][j]+1,0)>std::max(a[i+1][j]-a[i][j]+1,0))
{
r+=std::max(a[i+1][j]-a[i][j]+1,0);
i++;
}
else if(a[i][j+1]>a[i+1][j])
{
r+=std::max(a[i][j+1]-a[i][j]+1,0);
j++;
}
else
{
r+=std::max(a[i+1][j]-a[i][j]+1,0);
i++;
}
}
printf("%d %d %d\n",i,j,r);
}
printf("%d",r);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
20372 KB |
Output is correct |
2 |
Correct |
0 ms |
20372 KB |
Output is correct |
3 |
Correct |
0 ms |
20372 KB |
Output is correct |
4 |
Correct |
0 ms |
20372 KB |
Output is correct |
5 |
Correct |
0 ms |
20372 KB |
Output is correct |
6 |
Correct |
0 ms |
20372 KB |
Output is correct |
7 |
Correct |
0 ms |
20372 KB |
Output is correct |
8 |
Correct |
0 ms |
20372 KB |
Output is correct |
9 |
Correct |
0 ms |
20372 KB |
Output is correct |
10 |
Correct |
0 ms |
20372 KB |
Output is correct |
11 |
Correct |
0 ms |
20372 KB |
Output is correct |
12 |
Correct |
0 ms |
20372 KB |
Output is correct |
13 |
Correct |
0 ms |
20372 KB |
Output is correct |
14 |
Correct |
0 ms |
20372 KB |
Output is correct |
15 |
Correct |
0 ms |
20372 KB |
Output is correct |
16 |
Correct |
0 ms |
20372 KB |
Output is correct |
17 |
Correct |
0 ms |
20372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
20372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
20372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
628 ms |
20372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |