#include<bits/stdc++.h>
#include<stack>
#define endl '\n'
using namespace std;
long long n,m,k,num=0, a[1002][1002], s[1002][1002], b[1002];
stack< pair<long long,long long> >l[1002],r[1002];
long long ll[1003], rr[1003];
long long maxar()
{
num++;
long long i,j, ans=-1;
for(j=1;j<=m;j++)b[j]=s[1][j];
for(j=1;j<=m;j++)
{
while(!l[num].empty() && l[num].top().first>=b[j])
{
l[num].pop();
}
if(!l[num].empty())ll[j]=l[num].top().second;
else ll[j]=0;
l[num].push({b[j],j});
}
for(j=m;j>=1;j--)
{
while(!r[num].empty() && r[num].top().first>=b[j])
{
r[num].pop();
}
if(!r[num].empty())rr[j]=r[num].top().second;
else rr[j]=m+1;
r[num].push({b[j],j});
}
for(j=1;j<=m;j++)
{
ans=max(ans, b[j]*(rr[j]-ll[j]-1));
}
for(i=2;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(s[i][j]==0)b[j]=0;
else b[j]++;
}
while(!l[num].empty())l[num].pop();
while(!r[num].empty())r[num].pop();
for(j=1;j<=m;j++)
{
while(!l[num].empty() && l[num].top().first>=b[j])
{
l[num].pop();
}
if(!l[num].empty())ll[j]=l[num].top().second;
else ll[j]=0;
l[num].push({b[j],j});
}
for(j=m;j>=1;j--)
{
while(!r[num].empty() && r[num].top().first>=b[j])
{
r[num].pop();
}
if(!r[num].empty())rr[j]=r[num].top().second;
else rr[j]=m+1;
r[num].push({b[j],j});
}
for(j=1;j<=m;j++)
{
ans=max(ans, b[j]*(rr[j]-ll[j]-1));
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i,j,b,c,le,ri,mid,mini=1000000000000,maxi=0;
cin>>n>>m>>k;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
mini=min(mini, a[i][j]);
maxi=max(maxi, a[i][j]);
}
}
le=mini; ri=maxi+10;
while(le+1<ri)
{
mid=(le+ri)/2;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]>=mid)s[i][j]=1;
else s[i][j]=0;
}
}
c=maxar();
if(c>=k)le=mid;
else ri=mid;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]>=le)s[i][j]=1;
else s[i][j]=0;
}
}
c=maxar();
cout<<le<<" "<<c<<endl;;
}
Compilation message
burrow.cpp: In function 'int main()':
burrow.cpp:91:19: warning: unused variable 'b' [-Wunused-variable]
91 | long long i,j,b,c,le,ri,mid,mini=1000000000000,maxi=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1816 KB |
Output is correct |
4 |
Correct |
2 ms |
1748 KB |
Output is correct |
5 |
Correct |
2 ms |
1944 KB |
Output is correct |
6 |
Correct |
2 ms |
2004 KB |
Output is correct |
7 |
Correct |
2 ms |
1620 KB |
Output is correct |
8 |
Correct |
5 ms |
2620 KB |
Output is correct |
9 |
Correct |
11 ms |
3700 KB |
Output is correct |
10 |
Correct |
43 ms |
4176 KB |
Output is correct |
11 |
Correct |
92 ms |
5264 KB |
Output is correct |
12 |
Correct |
22 ms |
6612 KB |
Output is correct |
13 |
Correct |
59 ms |
3648 KB |
Output is correct |
14 |
Correct |
77 ms |
7884 KB |
Output is correct |
15 |
Correct |
78 ms |
7944 KB |
Output is correct |
16 |
Correct |
134 ms |
8468 KB |
Output is correct |
17 |
Correct |
55 ms |
10048 KB |
Output is correct |
18 |
Correct |
367 ms |
13776 KB |
Output is correct |
19 |
Correct |
241 ms |
14516 KB |
Output is correct |
20 |
Correct |
823 ms |
19804 KB |
Output is correct |
21 |
Correct |
742 ms |
22152 KB |
Output is correct |
22 |
Correct |
1118 ms |
27052 KB |
Output is correct |
23 |
Correct |
1123 ms |
27000 KB |
Output is correct |
24 |
Correct |
397 ms |
19468 KB |
Output is correct |
25 |
Correct |
354 ms |
20216 KB |
Output is correct |