#include <bits/stdc++.h>
using namespace std;
int m,n;
int a[1005][1005];
int b[1005][1005];
int minn[1005][1005];
int ans=-1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>m>>n;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
cin>>a[i][j];
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=a[i][j]-i-j;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++) {
minn[i][j]=min({minn[i-1][j],minn[i][j-1],b[i][j]});
ans=max(ans,a[i][j]-i-j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=a[i][j]-i+j;
for(int i=1; i<=m; i++)
for(int j=n; j>=1; j--) {
minn[i][j]=min({minn[i-1][j],minn[i][j+1],b[i][j]});
ans=max(ans,a[i][j]-i+j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=-a[i][j]-i-j;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++) {
minn[i][j]=min({minn[i-1][j],minn[i][j-1],b[i][j]});
ans=max(ans,-a[i][j]-i-j-minn[i][j]-1);
}
memset(minn,0x3f,sizeof(minn));
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
b[i][j]=-a[i][j]-i+j;
for(int i=1; i<=m; i++)
for(int j=n; j>=1; j--) {
minn[i][j]=min({minn[i-1][j],minn[i][j+1],b[i][j]});
ans=max(ans,-a[i][j]-i+j-minn[i][j]-1);
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4564 KB |
Output is correct |
10 |
Correct |
2 ms |
4564 KB |
Output is correct |
11 |
Correct |
3 ms |
4564 KB |
Output is correct |
12 |
Correct |
3 ms |
4564 KB |
Output is correct |
13 |
Correct |
3 ms |
4564 KB |
Output is correct |
14 |
Correct |
2 ms |
4564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4308 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4352 KB |
Output is correct |
8 |
Correct |
2 ms |
4308 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4564 KB |
Output is correct |
13 |
Correct |
2 ms |
4564 KB |
Output is correct |
14 |
Correct |
3 ms |
4564 KB |
Output is correct |
15 |
Correct |
3 ms |
4564 KB |
Output is correct |
16 |
Correct |
3 ms |
4564 KB |
Output is correct |
17 |
Correct |
2 ms |
4564 KB |
Output is correct |
18 |
Correct |
95 ms |
12136 KB |
Output is correct |
19 |
Correct |
105 ms |
20692 KB |
Output is correct |
20 |
Correct |
116 ms |
20332 KB |
Output is correct |
21 |
Correct |
100 ms |
20632 KB |
Output is correct |
22 |
Correct |
95 ms |
20636 KB |
Output is correct |
23 |
Correct |
110 ms |
20668 KB |
Output is correct |
24 |
Correct |
92 ms |
21044 KB |
Output is correct |