제출 #995658

#제출 시각아이디문제언어결과실행 시간메모리
995658LOLOLO호화 벙커 (IZhO13_burrow)C++17
100 / 100
1114 ms65536 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 1e3 + 10;
int n, m, k;
int is[N][N], pr[N], l[N], r[N];

int area() {
    stack <int> st;
    for (int i = 1; i <= m; i++) {
        while (sz(st) && pr[i] < pr[st.top()]) {
            st.pop();
        }

        l[i] = sz(st) ? st.top() : 0;
        st.push(i);
    }

    while (sz(st))
        st.pop();

    int ans = 0;
    for (int i = m; i >= 1; i--) {
        while (sz(st) && pr[i] <= pr[st.top()])
            st.pop();

        r[i] = sz(st) ? st.top() : m + 1;
        ans = max(ans, (r[i] - l[i] - 1) * pr[i]);
        st.push(i);
    }

    return ans;
}

int check() {
    mem(pr, 0);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (is[i][j]) {
                pr[j]++;
            } else {
                pr[j] = 0;
            }
        }

        ans = max(ans, area());
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m >> k;
    vector < vector <int>> cell;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x;
            cin >> x;
            cell.pb({x, i, j});
        }
    }

    sort(all(cell), greater <vector <int>>() );
    int l = 0, r = 1e9, m, ans = 0, area = 0;

    while (l <= r) {
        m = (l + r) / 2;
        mem(is, 0);
        for (int j = 0; j < sz(cell); j++) {
            if (cell[j][0] >= m) {
                is[cell[j][1]][cell[j][2]] = 1;
            } else {
                break;
            }
        }

        int v = check();
        if (v >= k) {
            ans = m;
            area = v;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }

    cout << ans << " " << area << '\n';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...