Submission #31908

# Submission time Handle Problem Language Result Execution time Memory
31908 2017-09-12T23:09:00 Z chonka K blocks (IZhO14_blocks) C++
0 / 100
143 ms 87964 KB
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std ;


#define MAXN 100007
#define MAXK 107

int n , k ;
long long a[ MAXN ] ;

long long dp[ MAXN ][ MAXK ] ;


long long val[ MAXN ] ;
long long pref[ MAXN ] ;
long long inf = 0 ;

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    int i ;
    inf = 1 ;
    for ( i = 1 ; i <= 15 ; i ++ ) {
        inf *= 10 ;
    }
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%lld" , &a[ i ] ) ;
    }
    a[ 0 ] = pref[ 0 ] = inf ;
}

void solve ( ) {
    int i , j ;
    stack < int > s ;
    for ( i = 1 ; i <= k ; i ++ ) {
        while ( s.empty ( ) == false ) { s.pop ( ) ; }
        s.push ( i - 1 ) ;
        a[ i - 1 ] = inf ;
        for ( j = i ; j <= n ; j ++ ) {
            while ( s.empty ( ) == false && a[ s.top ( ) ] <= a[ j ] ) {
                s.pop ( ) ;
            }
            val[ s.size ( ) ] = dp[ s.top ( ) ][ i - 1 ] + a[ j ] ;
            pref[ s.size ( ) ] = min ( pref[ s.size ( ) - 1 ] , val[ s.size ( ) ] ) ;
            dp[ j ][ i ] = pref[ s.size ( ) ] ;
            s.push ( j ) ;
        }
    }
    printf ( "%lld\n" , dp[ n ][ k ] ) ;
}


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

Compilation message

blocks.cpp: In function 'void input()':
blocks.cpp:21:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d%d" , &n , &k ) ;
                                ^
blocks.cpp:28:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%lld" , &a[ i ] ) ;
                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 87964 KB Output is correct
2 Incorrect 0 ms 87964 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 87964 KB Output is correct
2 Incorrect 0 ms 87964 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 87964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 87964 KB Output is correct
2 Correct 6 ms 87964 KB Output is correct
3 Correct 23 ms 87964 KB Output is correct
4 Incorrect 143 ms 87964 KB Output isn't correct
5 Halted 0 ms 0 KB -