Submission #4767

# Submission time Handle Problem Language Result Execution time Memory
4767 2014-01-01T08:58:39 Z gs13068 Luxury burrow (IZhO13_burrow) C++
100 / 100
812 ms 8916 KB
#include<cstdio>

int a[1000][1000];
int d[1000][1000];
int s[2000],p[2000],sn;
int n,m,k;

int possible(int x)
{
  int i,j,max=0;
  for(i=0;i<n;i++)
  {
    if(a[i][0]>=x)d[i][0]=1;
    else d[i][0]=0;
    for(j=1;j<m;j++)
    {
      if(a[i][j]>=x)d[i][j]=d[i][j-1]+1;
      else d[i][j]=0;
    }
  }
  for(j=0;j<m;j++)
  {
    sn=0;
    s[sn]=0;
    p[sn]=-1;
    sn++;
    for(i=0;i<n;i++)
    {
      while(sn&&s[sn-1]>=d[i][j])
      {
        if(max<s[sn-1]*(i-p[sn-2]-1))
          max=s[sn-1]*(i-p[sn-2]-1);
        sn--;
      }
      s[sn]=d[i][j];
      p[sn]=i;
      sn++;
    }
    while(sn)
    {
      if(max<s[sn-1]*(n-p[sn-2]-1))
        max=s[sn-1]*(n-p[sn-2]-1);
      sn--;
    }
  }
  return max;
}

int main()
{
  int l,r,mid;
  int i,j;
  scanf("%d%d%d",&n,&m,&k);
  for(i=0;i<n;i++)for(j=0;j<m;j++)scanf("%d",&a[i][j]);
  l=1;
  r=1000000000;
  while(l<r)
  {
    mid=(l+r+1)/2;
    if(possible(mid)>=k)l=mid;
    else r=mid-1;
  }
  printf("%d %d",l,possible(l));
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 8916 KB Output is correct
2 Correct 0 ms 8916 KB Output is correct
3 Correct 0 ms 8916 KB Output is correct
4 Correct 0 ms 8916 KB Output is correct
5 Correct 0 ms 8916 KB Output is correct
6 Correct 0 ms 8916 KB Output is correct
7 Correct 0 ms 8916 KB Output is correct
8 Correct 4 ms 8916 KB Output is correct
9 Correct 4 ms 8916 KB Output is correct
10 Correct 20 ms 8916 KB Output is correct
11 Correct 32 ms 8916 KB Output is correct
12 Correct 20 ms 8916 KB Output is correct
13 Correct 24 ms 8916 KB Output is correct
14 Correct 60 ms 8916 KB Output is correct
15 Correct 56 ms 8916 KB Output is correct
16 Correct 68 ms 8916 KB Output is correct
17 Correct 72 ms 8916 KB Output is correct
18 Correct 252 ms 8916 KB Output is correct
19 Correct 372 ms 8916 KB Output is correct
20 Correct 600 ms 8916 KB Output is correct
21 Correct 644 ms 8916 KB Output is correct
22 Correct 808 ms 8916 KB Output is correct
23 Correct 812 ms 8916 KB Output is correct
24 Correct 548 ms 8916 KB Output is correct
25 Correct 680 ms 8916 KB Output is correct