# include <iostream>
# include <algorithm>
using namespace std;
const long long INF=1e18;
const int MAX=1e3+11;
int n,m;
long long a[MAX][MAX];
long long mini[MAX][MAX];
long long maxi[MAX][MAX];
void read()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) cin>>a[i][j];
}
}
void reset()
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
mini[i][j]=INF;
maxi[i][j]-=INF;
}
}
}
long long get_ans()
{
reset();
long long ans=-1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
mini[i][j]=min(mini[i][j-1],mini[i-1][j]);
mini[i][j]=min(mini[i][j],a[i][j]-i-j);
maxi[i][j]=max(maxi[i][j-1],maxi[i-1][j]);
maxi[i][j]=max(maxi[i][j],a[i][j]+i+j);
ans=max(ans,a[i][j]-i-j-mini[i][j]);
ans=max(ans,maxi[i][j]-i-j-a[i][j]);
//cout<<i<<" "<<j<<":"<<mini[i][j]<<" "<<maxi[i][j]<<"\n";
}
}
//cout<<"->"<<ans<<"\n";
return ans;
}
void solve()
{
long long ans=0;
ans=max(ans,get_ans());
for(int i=1;i<=n;i++) reverse(a[i]+1,a[i]+1+m);
ans=max(ans,get_ans());
cout<<ans-1<<"\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
464 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
87 ms |
32508 KB |
Output is correct |
19 |
Correct |
78 ms |
32576 KB |
Output is correct |
20 |
Correct |
72 ms |
32320 KB |
Output is correct |
21 |
Correct |
83 ms |
32592 KB |
Output is correct |
22 |
Correct |
89 ms |
32588 KB |
Output is correct |
23 |
Correct |
77 ms |
32684 KB |
Output is correct |
24 |
Correct |
77 ms |
32164 KB |
Output is correct |