#include <stdio.h>
#define inf 0x7fffffff
int n, m, k, a[1001][1001], mmax, mmin=inf, ans1, ans2, s[1001][2], top, h[1001];
void input(void)
{
int i, j;
scanf("%d %d %d",&n,&m,&k);
for(i=1 ; i<=n ; i++)
for(j=1 ; j<=m ; j++)
{
scanf("%d",&a[i][j]);
if(mmax<a[i][j])
mmax=a[i][j];
if(mmin>a[i][j])
mmin=a[i][j];
}
}
int find_rec(int num)
{
int i, j, l, x, res=0;
for(i=1 ; i<=m ; i++)
h[i]=0;
for(i=1 ; i<=n ; i++)
{
for(j=1 ; j<=m ; j++)
{
if(a[i][j]>=num)
h[j]++;
else
h[j]=0;
}
top=0;
for(j=1 ; j<=m ; j++)
{
x=j;
while(top && s[top][0]>=h[j])
{
x=s[top][1];
top--;
}
if(h[j])
{
s[++top][0]=h[j];
s[top][1]=x;
}
for(l=1 ; l<=top ; l++)
{
x=s[l][0]*(j-s[l][1]+1);
if(res<x)
res=x;
}
}
}
return res;
}
void process(void)
{
int left=mmin, mid, right=mmax, temp;
while(left<=right)
{
mid=(left+right)/2;
temp=find_rec(mid);
if(temp>=k)
{
ans1=mid;
ans2=temp;
left=mid+1;
}
else
right=mid-1;
}
}
void output(void)
{
printf("%d %d",ans1,ans2);
}
int main(void)
{
input();
process();
output();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5012 KB |
Output is correct |
2 |
Correct |
0 ms |
5012 KB |
Output is correct |
3 |
Correct |
0 ms |
5012 KB |
Output is correct |
4 |
Correct |
0 ms |
5012 KB |
Output is correct |
5 |
Correct |
0 ms |
5012 KB |
Output is correct |
6 |
Correct |
0 ms |
5012 KB |
Output is correct |
7 |
Correct |
0 ms |
5012 KB |
Output is correct |
8 |
Correct |
0 ms |
5012 KB |
Output is correct |
9 |
Correct |
0 ms |
5012 KB |
Output is correct |
10 |
Correct |
8 ms |
5012 KB |
Output is correct |
11 |
Correct |
40 ms |
5012 KB |
Output is correct |
12 |
Correct |
8 ms |
5012 KB |
Output is correct |
13 |
Correct |
24 ms |
5012 KB |
Output is correct |
14 |
Correct |
40 ms |
5012 KB |
Output is correct |
15 |
Correct |
44 ms |
5012 KB |
Output is correct |
16 |
Correct |
72 ms |
5012 KB |
Output is correct |
17 |
Correct |
36 ms |
5012 KB |
Output is correct |
18 |
Correct |
220 ms |
5012 KB |
Output is correct |
19 |
Correct |
148 ms |
5012 KB |
Output is correct |
20 |
Correct |
416 ms |
5012 KB |
Output is correct |
21 |
Correct |
400 ms |
5012 KB |
Output is correct |
22 |
Correct |
520 ms |
5012 KB |
Output is correct |
23 |
Correct |
580 ms |
5012 KB |
Output is correct |
24 |
Correct |
228 ms |
5012 KB |
Output is correct |
25 |
Correct |
172 ms |
5012 KB |
Output is correct |