Submission #897008

#TimeUsernameProblemLanguageResultExecution timeMemory
897008borisAngelovLuxury burrow (IZhO13_burrow)C++17
100 / 100
461 ms14044 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; const int inf = 1e9 + 7; int n, m, k; int a[maxn][maxn]; int minHeight = inf, maxHeight = -inf; int height[maxn]; int prv[maxn]; int nxt[maxn]; int calcRectangle() { stack<int> stprv; for (int i = 1; i <= m; ++i) { while (!stprv.empty() && height[stprv.top()] >= height[i]) { stprv.pop(); } if (!stprv.empty()) { prv[i] = stprv.top(); } else { prv[i] = 0; } stprv.push(i); } stack<int> stnxt; for (int i = m; i >= 1; --i) { while (!stnxt.empty() && height[stnxt.top()] >= height[i]) { stnxt.pop(); } if (!stnxt.empty()) { nxt[i] = stnxt.top(); } else { nxt[i] = m + 1; } stnxt.push(i); } int ans = 0; for (int i = 1; i <= m; ++i) { ans = max(ans, height[i] * (nxt[i] - prv[i] - 1)); } return ans; } int area = 0; bool check(int leastHeight) { for (int i = 1; i <= m; ++i) { height[i] = 0; } area = -1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (a[i][j] >= leastHeight) { ++height[j]; } else { height[j] = 0; } } int res = calcRectangle(); area = max(area, res); } return area >= k; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; minHeight = min(minHeight, a[i][j]); maxHeight = max(maxHeight, a[i][j]); } } int l = minHeight; int r = maxHeight; while (l <= r) { int mid = (l + r) / 2; if (check(mid) == true) { l = mid + 1; } else { r = mid - 1; } } check(r); cout << r << ' ' << area << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...