This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
const int N = 1 << 10;
const int INF = 1e18;
int n;
int m;
int a[N][N];
void rot() {
for (int i = 0; i < N; ++i) {
for (int j = i; j < N; ++j) {
swap(a[i][j], a[j][i]);
}
}
swap(n, m);
for (int i = 0; i < n; ++i) {
reverse(a[i], a[i] + m);
}
}
int answer = -1;
int dp[N][N];
void solve() {
fill_n(dp[0], N * N, INF);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i][j] = a[i][j] - i - j;
if (i) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
}
if (j) {
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
answer = max(answer, a[i][j] - i - j - 1 - dp[i][j]);
}
}
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
for (int it = 0; it < 4; ++it) {
if (it) {
rot();
}
solve();
}
cout << answer << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |