#include <bits/stdc++.h>
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e3 + 5;
const int inf = 1e9 + 7;
int n, m, dist, a[N][N], cur, mx, ans = -inf, dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
dp[i][0] = inf;
dp[i][m + 1] = inf;
for(int j = 1; j <= m; ++j){
cin >> a[i][j];
dp[i][j] = a[i][j];
}
}
for(int j = 1; j <= m; ++j){
dp[0][j] = inf;
dp[n + 1][j] = inf;
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
}
}
for(int i = 1; i <= n; ++i){
for(int j = m; j >= 1; --j){
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j + 1] + 1);
}
}
for(int i = n; i >= 1; --i){
for(int j = 1; j <= m; ++j){
dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
}
}
for(int i = n; i >= 1; --i){
for(int j = m; j >= 1; --j){
dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j + 1] + 1);
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
ans = max(ans, a[i][j] - dp[i][j] - 1);
}
}
cout << ans;
return 0;
}
Compilation message
maxcomp.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("g", on)
|
maxcomp.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization("03")
|
maxcomp.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization("unroll-loops")
|
maxcomp.cpp:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
7 | #pragma comment(linker, "/stack:200000000")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
668 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
668 KB |
Output is correct |
13 |
Correct |
1 ms |
716 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
1 ms |
716 KB |
Output is correct |
18 |
Correct |
114 ms |
8260 KB |
Output is correct |
19 |
Correct |
90 ms |
8132 KB |
Output is correct |
20 |
Correct |
89 ms |
8200 KB |
Output is correct |
21 |
Correct |
111 ms |
8360 KB |
Output is correct |
22 |
Correct |
92 ms |
8248 KB |
Output is correct |
23 |
Correct |
93 ms |
8240 KB |
Output is correct |
24 |
Correct |
94 ms |
7844 KB |
Output is correct |