# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491208 | Vladikus004 | Luxury burrow (IZhO13_burrow) | C++14 | 2 ms | 332 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 mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 2e9
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 1000 + 3;
int n, m, k, a[N][N], h[N][N];
int check(int x) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
h[i][j] = (a[i][j] >= x);
for (int i = 1; i < n; i++)
for (int j = 0; j < m; j++)
if (h[i][j])
h[i][j] += h[i - 1][j];
int mx = 0;
for (int i = 0; i < n; i++) {
stack <int> st;
for (int j = 0; j < m; j++) {
while (sz(st) && h[i][st.top()] >= h[i][j]) st.pop();
int ws;
if (sz(st)) ws = st.top();
else ws = -1;
st.push(j);
mx = max(mx, h[i][j] * (j - ws));
}
while (sz(st)) st.pop();
for (int j = m - 1; j >= 0; j--) {
while (sz(st) && h[i][st.top()] >= h[i][j]) st.pop();
int ws;
if (sz(st)) ws = st.top();
else ws = m;
st.push(j);
mx = max(mx, h[i][j] * (ws - j));
}
}
if (mx < k) return 0;
return mx;
}
void solve() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int l = 1, r = 1000000000 + 7;
while (l < r) {
int mid = (l + r) / 2;
if (check(mid)) l = mid + 1;
else r = mid;
}
cout << l - 1 << " " << check(l - 1);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
freopen("burrow.in", "r", stdin);
freopen("burrow.out", "w", stdout);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |