Submission #491208

# Submission time Handle Problem Language Result Execution time Memory
491208 2021-11-30T18:08:31 Z Vladikus004 Luxury burrow (IZhO13_burrow) C++14
0 / 100
2 ms 332 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;
}

Compilation message

burrow.cpp: In function 'int32_t main()':
burrow.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen("burrow.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
burrow.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     freopen("burrow.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -