#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
const int N = 1005;
int n, m;
int a[N][N];
int pref1[N][N];
int pref2[N][N];
int pref3[N][N];
int pref4[N][N];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
pref1[i][j] = a[i][j] + i + j;
if (i > 0) pref1[i][j] = min(pref1[i][j], pref1[i - 1][j]);
if (j > 0) pref1[i][j] = min(pref1[i][j], pref1[i][j - 1]);
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < m; j++) {
pref2[i][j] = a[i][j] + i + j;
if (i + 1 < n) pref2[i][j] = min(pref2[i][j], pref2[i + 1][j]);
if (j > 0) pref2[i][j] = min(pref2[i][j], pref2[i][j - 1]);
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
pref3[i][j] = a[i][j] + i + j;
if (i > 0) pref3[i][j] = min(pref3[i][j], pref3[i - 1][j]);
if (j + 1 < m) pref3[i][j] = min(pref3[i][j], pref3[i][j + 1]);
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
pref4[i][j] = a[i][j] + i + j;
if (i + 1 < n) pref4[i][j] = min(pref4[i][j], pref4[i + 1][j]);
if (j + 1 < m) pref4[i][j] = min(pref4[i][j], pref4[i][j + 1]);
}
}
int ans = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans = max(ans, a[i][j] - i - j - pref1[i][j] - 1);
ans = max(ans, a[i][j] + i - j - pref2[i][j] - 1);
ans = max(ans, a[i][j] - i + j - pref3[i][j] - 1);
ans = max(ans, a[i][j] + i + j - pref4[i][j] - 1);
}
}
cout << ans << '\n';
return 0;
}
Compilation message
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |