# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
537992 | GioChkhaidze | Luxury burrow (IZhO13_burrow) | C++14 | 394 ms | 17932 KiB |
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 <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1003;
int n, m, k, ans_c, ans_a, a[N][N], b[N][N];
bool check(int x) {
for (int i = n; i >= 1; --i)
for (int j = m; j >= 1; --j)
if (a[i][j] >= x) b[i][j] = b[i + 1][j] + 1;
else b[i][j] = 0;
int area = 0;
deque < pair < int , int > > dq;
for (int i = 1; i <= n; ++i) {
for (int j = m; j >= 1; --j) {
int id = j;
while (dq.size() && dq.back().f >= b[i][j]) {
area = max(area, dq.back().f * (dq.back().s - j));
id = dq.back().s;
dq.pop_back();
}
area = max(area, b[i][j] * (id - j + 1));
dq.push_back({b[i][j], id});
}
while (dq.size()) {
area = max(area, dq.back().f * dq.back().s);
dq.pop_back();
}
}
if (area >= k) {
ans_c = x;
ans_a = area;
return true;
}
return false;
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> a[i][j];
int l = 1, r = 1e9, mid;
while (l <= r) {
mid = ((l + r) >> 1);
if (check(mid))
l = mid + 1;
else
r = mid - 1;
}
cout << ans_c << " " << ans_a << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |