Submission #491206

# Submission time Handle Problem Language Result Execution time Memory
491206 2021-11-30T18:08:12 Z Vladikus004 Luxury burrow (IZhO13_burrow) C++14
0 / 100
1 ms 460 KB
#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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Incorrect 1 ms 460 KB Output isn't correct
6 Halted 0 ms 0 KB -