Submission #895255

#TimeUsernameProblemLanguageResultExecution timeMemory
895255AndreyLuxury burrow (IZhO13_burrow)C++14
100 / 100
877 ms18168 KiB
#include<bits/stdc++.h>
using namespace std;

int n,m;
int table[1001][1001];
int wow[1001][1001];

int solve(int col) {
    long long big = 0,a;
    vector<long long> haha(m);
    vector<long long> ans(m,1);
    for(long long i = 0; i < m; i++) {
        haha[i] = table[col][i];
    }
    stack<pair<long long,long long>> idk;
    idk.push({-1,-1});
    for(long long i = 0; i < m; i++) {
        a = haha[i];
        while(a <= idk.top().first) {
            idk.pop();
        }
        ans[i]+=i-idk.top().second-1;
        idk.push({a,i});
    }
    while(!idk.empty()) {
        idk.pop();
    }
    idk.push({-1,m});
    for(long long i = m-1; i >= 0; i--) {
        a = haha[i];
        while(a <= idk.top().first) {
            idk.pop();
        }
        ans[i]+=idk.top().second-i-1;
        idk.push({a,i});
    }
    for(long long i = 0; i < m; i++) {
        big = max(big,haha[i]*ans[i]);
    }
    return big;
}

int calc(int a) {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(wow[i][j] >= a) {
                table[i][j] = 1;
            }
            else {
                table[i][j] = 0;
            }
        }
    }
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(table[i][j] == 1) {
                table[i][j] = table[i-1][j]+1;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans = max(ans,solve(i));
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k;
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> wow[i][j];
        }
    }
    int l = 0,r = 1e9;
    while(l < r) {
        int mid = (l+r+1)/2;
        if(calc(mid) >= k) {
            l = mid;
        }
        else {
            r = mid-1;
        }
    }
    cout << l << " " << calc(l);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...