Submission #963337

#TimeUsernameProblemLanguageResultExecution timeMemory
963337biankMaxcomp (info1cup18_maxcomp)C++14
100 / 100
304 ms4408 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) int(x.size()) #define all(x) begin(x),end(x) const int INF = 2e9; struct STree { int n; vector<int> st; STree(int _n) : n(_n), st(2 * n, -INF) {} void update(int p, int val) { p += n; if (st[p] < val) { st[p] = val; while (p /= 2) { st[p] = max(st[2 * p], st[2 * p + 1]); } } } int query(int l, int r) { int res = -INF; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l & 1) res = max(res, st[l++]); if (r & 1) res = max(st[--r], res); } return res; } }; int solve(vector<vector<int>> &a) { int n = sz(a), m = sz(a[0]); STree sum(m), sub(m); int ans = -INF; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { sum.update(j, a[i][j] + i + j); sub.update(j, -a[i][j] + i + j); ans = max({ans, sum.query(0, j + 1) - i - j - a[i][j] - 1, a[i][j] - i - j + sub.query(0, j + 1) - 1}); } } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int ans = solve(a); for (int i = 0; i < n; i++) { reverse(all(a[i])); } ans = max(ans, solve(a)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...