#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
lld abs(lld a){
if(a>0)return a;
return -a;
}
int main(){
int n,m;
cin>>n>>m;
lld matrix[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>matrix[i][j];
}
}
lld B[n][m];
lld ans=-1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
B[i][j]=matrix[i][j]-i-j;
}
}
lld minB[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
minB[i][j]=B[i][j];
if(i>0)minB[i][j]=min(minB[i][j],minB[i-1][j]);
if(j>0)minB[i][j]=min(minB[i][j],minB[i][j-1]);
ans=max(ans,B[i][j]-minB[i][j]-1);
}
}
for(int i=0;i<n;i++){
for(int j=m-1;j>-1;j--){
B[i][j]=matrix[i][j]-i+j;
}
}
for(int i=0;i<n;i++){
for(int j=m-1;j>-1;j--){
minB[i][j]=B[i][j];
if(i>0)minB[i][j]=min(minB[i][j],minB[i-1][j]);
if(j<m-1)minB[i][j]=min(minB[i][j],minB[i][j+1]);
ans=max(ans,B[i][j]-minB[i][j]-1);
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |