답안 #38671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38671 2018-01-05T20:25:08 Z chonka 호화 벙커 (IZhO13_burrow) C++
100 / 100
843 ms 5992 KB
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std ;

#define MAXN 1007

int n , m , k ;
int a[ MAXN ][ MAXN ] ;
int h[ MAXN ] ;

int st[ MAXN ] ;
int en[ MAXN ] ;
int ans ;

bool f ( int x ) {
    int i , j ;
    int mx = 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 ] >= x ) {
                h[ j ] ++ ;
            }
            else { h[ j ] = 0 ; }
        }
        stack < int > s ;
        while ( s.empty ( ) == false ) { s.pop ( ) ; }
        h[ 0 ] = h[ m + 1 ] = -1 ;
        s.push ( 0 ) ;
        for ( j = 1 ; j <= m ; j ++ ) {
            while ( h[ s.top ( ) ] >= h[ j ] ) { s.pop ( ) ; }
            st[ j ] = s.top ( ) ;
            s.push ( j ) ;
        }
        while ( s.empty ( ) == false ) { s.pop ( ) ; }
        s.push ( m + 1 ) ;
        for ( j = m ; j >= 1 ; j -- ) {
            while ( h[ s.top ( ) ] >= h[ j ] ) { s.pop ( ) ; }
            en[ j ] = s.top ( ) ;
            s.push ( j ) ;
        }
        for ( j = 1 ; j <= m ; j ++ ) {
            int cur = h[ j ] * ( en[ j ] - st[ j ] - 1 ) ;
            if ( mx < cur ) { mx = cur ; }
        }
    }
    ans = mx ;
    return ( mx >= k ) ;
}

void input ( ) {
    scanf ( "%d%d%d" , &n , &m , &k ) ;
    int i , j ;
    for ( i = 1 ; i <= n ; i ++ ) {
        for ( j = 1 ; j <= m ; j ++ ) {
            scanf ( "%d" , &a[ i ][ j ] ) ;
        }
    }
}

void solve ( ) {
    int l , r , mid ;
    l = 1 ;
    r = 1 ;
    for ( mid = 1 ; mid <= 9 ; mid ++ ) { r *= 10 ; }
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) == true ) { l = mid ; }
        else { r = mid ; }
    }
    while ( f ( r ) == false ) { r -- ; }
    printf ( "%d %d\n" , r , ans ) ;
}

int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

Compilation message

burrow.cpp: In function 'void input()':
burrow.cpp:53:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d%d" , &n , &m , &k ) ;
                                       ^
burrow.cpp:57:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf ( "%d" , &a[ i ][ j ] ) ;
                                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5992 KB Output is correct
2 Correct 0 ms 5992 KB Output is correct
3 Correct 0 ms 5992 KB Output is correct
4 Correct 0 ms 5992 KB Output is correct
5 Correct 0 ms 5992 KB Output is correct
6 Correct 0 ms 5992 KB Output is correct
7 Correct 0 ms 5992 KB Output is correct
8 Correct 6 ms 5992 KB Output is correct
9 Correct 9 ms 5992 KB Output is correct
10 Correct 33 ms 5992 KB Output is correct
11 Correct 66 ms 5992 KB Output is correct
12 Correct 33 ms 5992 KB Output is correct
13 Correct 43 ms 5992 KB Output is correct
14 Correct 99 ms 5992 KB Output is correct
15 Correct 96 ms 5992 KB Output is correct
16 Correct 113 ms 5992 KB Output is correct
17 Correct 103 ms 5992 KB Output is correct
18 Correct 323 ms 5992 KB Output is correct
19 Correct 349 ms 5992 KB Output is correct
20 Correct 683 ms 5992 KB Output is correct
21 Correct 646 ms 5992 KB Output is correct
22 Correct 843 ms 5992 KB Output is correct
23 Correct 836 ms 5992 KB Output is correct
24 Correct 539 ms 5992 KB Output is correct
25 Correct 519 ms 5992 KB Output is correct