답안 #13077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
13077 2015-01-30T17:34:41 Z dohyun0324 호화 벙커 (IZhO13_burrow) C++
100 / 100
813 ms 9068 KB
#include<stdio.h>
int n,m,k,a[1010][1010],b[1010][1010],arr1[1010],arr2[1010],top;
struct data
{
    int x,p;
}st[1010];
int pro(int x)
{
    int w,i,j,l,p=1,maxi=0;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(a[i][j]>=x) b[i][j]=1;
            else b[i][j]=0;
        }
    }
    for(i=1;i<=m;i++){
        p=1;
        for(j=1;j<=n+1;j++){
            if(b[j][i]==0){
                w=0;
                for(l=j-1;l>=p;l--){
                    if(b[l][i]==0) break;
                    b[l][i]=++w;
                }
                p=j;
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            while(st[top].x>b[i][j] && top>0){arr1[st[top].p]=j-1; top--;}
            top++;
            st[top].x=b[i][j]; st[top].p=j;
        }
        while(top>0){arr1[st[top].p]=m; top--;}
        for(j=m;j>=1;j--){
            while(st[top].x>b[i][j] && top>0){arr2[st[top].p]=j+1; top--;}
            top++;
            st[top].x=b[i][j]; st[top].p=j;
        }
        while(top>0){arr2[st[top].p]=1; top--;}
        for(j=1;j<=m;j++){
            if(maxi<(arr1[j]-arr2[j]+1)*b[i][j]) maxi=(arr1[j]-arr2[j]+1)*b[i][j];
        }
    }
    return maxi;
}
void bsearch()
{
    int p,s=1,e=1000000000,mid;
    while(1){
        if(s==e) break;
        mid=(s+e)/2;
        p=pro(mid);
        if(p>=k) s=mid+1;
        else e=mid;
    }
    if(pro(s)>=k) s++;
    printf("%d %d",s-1,pro(s-1));
}
int main()
{
    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]);
        }
    }
    bsearch();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9068 KB Output is correct
2 Correct 0 ms 9068 KB Output is correct
3 Correct 1 ms 9068 KB Output is correct
4 Correct 0 ms 9068 KB Output is correct
5 Correct 0 ms 9068 KB Output is correct
6 Correct 0 ms 9068 KB Output is correct
7 Correct 0 ms 9068 KB Output is correct
8 Correct 7 ms 9068 KB Output is correct
9 Correct 13 ms 9068 KB Output is correct
10 Correct 38 ms 9068 KB Output is correct
11 Correct 62 ms 9068 KB Output is correct
12 Correct 36 ms 9068 KB Output is correct
13 Correct 42 ms 9068 KB Output is correct
14 Correct 96 ms 9068 KB Output is correct
15 Correct 105 ms 9068 KB Output is correct
16 Correct 111 ms 9068 KB Output is correct
17 Correct 116 ms 9068 KB Output is correct
18 Correct 293 ms 9068 KB Output is correct
19 Correct 338 ms 9068 KB Output is correct
20 Correct 686 ms 9068 KB Output is correct
21 Correct 622 ms 9068 KB Output is correct
22 Correct 763 ms 9068 KB Output is correct
23 Correct 813 ms 9068 KB Output is correct
24 Correct 535 ms 9068 KB Output is correct
25 Correct 596 ms 9068 KB Output is correct