This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
vector<vector<int>> a(n + 2, vector<int>(m + 2)), dp(n + 2, vector<int>(m + 2));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = a[i][j];
dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
dp[i][j] = max(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] = max(dp[i][j], dp[i + 1][j] - 1);
dp[i][j] = max(dp[i][j], dp[i][j + 1] - 1);
}
}
int ans = -1e9;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ans = max(ans, dp[i][j] - a[i][j] - 1);
}
}
cout << ans << '\n';
}
# | 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... |