#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 = 1e2 + 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")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |