제출 #963294

#제출 시각아이디문제언어결과실행 시간메모리
963294biankMaxcomp (info1cup18_maxcomp)C++14
15 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; 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 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]; } } 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}); } } 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...