# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
518327 | ioilolcom | Luxury burrow (IZhO13_burrow) | C++14 | 1022 ms | 18596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pii pair<int,int>
#define pb push_back
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define mp make_pair
typedef long long int ll;
int nn,m,k;
const int N=1050;
int g[N][N];
int histogram( vector<int> vv){
vector<int> a;
a.push_back(0);
for(int e:vv) {
a.push_back(e);
}
int n=sz(a)-1;
vector<int> rt(n+1);
vector<int> lft(n+1);
vector<pair<int,int> > v;
for(int i=1; i<=n; i++) {
while(sz(v)&&v.back().first>=a[i]) {
v.pop_back();
}
if(sz(v)) {
lft[i]=v.back().second+1;
}
else{
lft[i]=1;
}
v.push_back(mp(a[i],i));
}
v.clear();
for(int i=n; i>=1; i--) {
while(sz(v)&&v.back().first>=a[i]) {
v.pop_back();
}
if(sz(v)) {
rt[i]=v.back().second-1;
}
else{
rt[i]=n;
}
v.push_back(mp(a[i],i));
}
int mx=0;
for(int i=1; i<=n; i++) {
mx=max(mx,a[i]*(rt[i]-lft[i]+1));
}
return mx;
}
pair<bool,int> check(int x){
vector<vector<int> > gr(N,vector<int> (N,0));
for(int i=1; i<=nn; i++) {
for(int j=1; j<=m; j++) {
gr[i][j]= (g[i][j]>=x);
}
}
int maxi=0;
vector<int> dp(N);
for(int i=1; i<=nn; i++) {
for(int j=1; j<=m; j++) {
if(gr[i][j]) {
dp[j]++;
}
else{
dp[j]=0;
}
}
int ans=histogram(dp);
maxi=max(maxi,ans);
}
return {maxi>=k,maxi};
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
cin>>nn>>m>>k;
for(int i=1; i<=nn; i++) {
for(int j=1; j<=m; j++) {
cin>>g[i][j];
}
}
int ans=1;
int area=0;
int l=1;
int r=1e9;
while(l<=r) {
int mid=(l+r)/2;
auto info=check(mid);
if(info.first) {
if(mid==ans) {
area=max(area,info.second);
}
else{
ans=mid;
area=info.second;
}
l=mid+1;
}
else{
r=mid-1;
}
}
cout<<ans<<" "<<area<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |