제출 #90569

#제출 시각아이디문제언어결과실행 시간메모리
90569popovicirobertLuxury burrow (IZhO13_burrow)C++14
100 / 100
513 ms54748 KiB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = 1000;

int mat[MAXN + 1][MAXN + 1];
int up[MAXN + 1][MAXN + 1];
int stk[MAXN + 1], l[MAXN + 1], r[MAXN + 1];
int n, m, k;

inline int check(int val) {
    int ans = 0;
    int i, j;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            up[i][j] = (up[i - 1][j] + 1) * (mat[i][j] >= val);
        }
        int sz = 0;
        stk[0] = 0;
        for(j = 1; j <= m; j++) {
            while(sz > 0 && up[i][stk[sz]] >= up[i][j]) {
                sz--;
            }
            l[j] = stk[sz];
            stk[++sz] = j;
        }
        sz = 0;
        stk[0] = m + 1;
        for(j = m; j >= 1; j--) {
            while(sz > 0 && up[i][stk[sz]] >= up[i][j]) {
                sz--;
            }
            r[j] = stk[sz];
            stk[++sz] = j;
        }
        for(j = 1; j <= m; j++) {
            ans = max(ans, up[i][j] * (r[j] - l[j] - 1));
        }
    }
    return ans;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m >> k;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            cin >> mat[i][j];
        }
    }
    int res = 0;
    for(int step = 1 << 30; step; step >>= 1) {
        if(check(res + step) >= k) {
            res += step;
        }
    }
    cout << res << " " << check(res);
    //cin.close();
    //cout.close();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...