Submission #1170258

#TimeUsernameProblemLanguageResultExecution timeMemory
1170258mnbvcxz123Luxury burrow (IZhO13_burrow)C++20
100 / 100
384 ms9388 KiB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;

constexpr int N=1005;

int n,m,k;
int a[N][N];
bool g[N][N];

pi ans;

bool check(int mid){
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            g[i][j]=0;
            if(a[i][j]<mid)g[i][j]=1;
        }
    vector<int>d(m+5,0),l(m+5,0),r(m+5,m+1);
    int ret=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j)
            if(g[i][j])d[j]=i;
        stack<int>s;
        for(int j=1;j<=m;++j){
            while(!s.empty() and d[s.top()]<=d[j])s.pop();
            if(s.empty())l[j]=0;
            else l[j]=s.top();
            s.push(j);
        }
        while(!s.empty())s.pop();
        for(int j=m;j>=1;--j){
            while(!s.empty() and d[s.top()]<=d[j])s.pop();
            if(s.empty())r[j]=m+1;
            else r[j]=s.top();
            s.push(j);
        }
        for(int j=1;j<=m;++j)ret=max(ret,(i-d[j])*(r[j]-l[j]-1));
    }
    if(ret<k)return 0;
    ans=max(ans,{mid,ret});
    return 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>n>>m>>k;
    vector<int>v;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            cin>>a[i][j];
            v.push_back(a[i][j]);
        }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    int l=0,r=v.size()-1,mid;
    while(l<=r){
        mid=(l+r)>>1;
        if(check(v[mid]))l=mid+1;
        else r=mid-1;
    }
    cout<<ans.first<<' '<<ans.second<<'\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...