#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,m,ans;
int arr[1005][1005];
int maxi[1005][1005];
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> arr[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
maxi[i][j] = arr[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
maxi[i][j] = max(maxi[i][j],maxi[i-1][j]-1);
}
for(int j=1;j<=m;j++){
maxi[i][j] = max(maxi[i][j],maxi[i][j-1]-1);
}
for(int j=m;j>=1;j--){
maxi[i][j] = max(maxi[i][j],maxi[i][j+1]-1);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans = max(ans,maxi[i][j]-arr[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
maxi[i][j] = arr[i][j];
}
}
for(int i=n;i>=1;i--){
for(int j=1;j<=m;j++){
maxi[i][j] = max(maxi[i][j],maxi[i+1][j]-1);
}
for(int j=1;j<=m;j++){
maxi[i][j] = max(maxi[i][j],maxi[i][j-1]-1);
}
for(int j=m;j>=1;j--){
maxi[i][j] = max(maxi[i][j],maxi[i][j+1]-1);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans = max(ans,maxi[i][j]-arr[i][j]);
}
}
cout << ans-1LL << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
732 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
728 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
732 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
728 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
732 KB |
Output is correct |
18 |
Correct |
84 ms |
24532 KB |
Output is correct |
19 |
Correct |
85 ms |
24600 KB |
Output is correct |
20 |
Correct |
89 ms |
24256 KB |
Output is correct |
21 |
Correct |
90 ms |
24524 KB |
Output is correct |
22 |
Correct |
97 ms |
24564 KB |
Output is correct |
23 |
Correct |
94 ms |
24500 KB |
Output is correct |
24 |
Correct |
83 ms |
24568 KB |
Output is correct |