답안 #32219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32219 2017-10-04T10:43:11 Z chonka K개의 묶음 (IZhO14_blocks) C++
100 / 100
693 ms 87832 KB
#include<iostream>
#include<stdio.h>
#include<stack>
#include<cstring>
using namespace std ;

#define inf 1000000007
#define MAXN 100007
#define MAXK 107

int n , k ;
int a[ MAXN ] ;

long long dp[ MAXN ][ MAXK ] ;


long long vals[ MAXN ] ;
long long pref[ MAXN ] ;

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

void solve ( ) {
    stack < pair < int , int > > s ;
    int sz ;
    int i , j ;
    for ( i = 0 ; i <= n ; i ++ ) {
        for ( j = 0 ; j <= k ; j ++ ) {
            dp[ i ][ j ] = inf ;
        }
    }
    dp[ 0 ][ 0 ] = 0 ;
    for ( j = 1 ; j <= k ; j ++ ) {
        while ( s.empty ( ) == false ) { s.pop ( ) ; }
        s.push ( make_pair ( inf , inf ) ) ;
        for ( i = 1 ; i <= n ; i ++ ) {
            long long aux = dp[ i - 1 ][ j - 1 ] ;
            while ( s.empty ( ) == false && s.top( ).first <= a[ i ] ) {
                aux = min ( aux , 1LL * s.top().second ) ;
                s.pop ( ) ;
            }
            dp[ i ][ j ] = min ( 1LL * s.top( ).first + s.top ( ).second , aux + a[ i ] ) ;
            if ( aux + a[ i ] < s.top ( ).first + s.top ( ).second ) {
                s.push ( make_pair ( a[ i ] , aux ) ) ;
            }
        }
    }
    printf ( "%lld\n" , dp[ n ][ k ] ) ;
}


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

Compilation message

blocks.cpp: In function 'void solve()':
blocks.cpp:30:9: warning: unused variable 'sz' [-Wunused-variable]
     int sz ;
         ^
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:24:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 87572 KB Output is correct
2 Correct 0 ms 87572 KB Output is correct
3 Correct 0 ms 87572 KB Output is correct
4 Correct 0 ms 87572 KB Output is correct
5 Correct 0 ms 87572 KB Output is correct
6 Correct 0 ms 87572 KB Output is correct
7 Correct 0 ms 87572 KB Output is correct
8 Correct 0 ms 87572 KB Output is correct
9 Correct 0 ms 87572 KB Output is correct
10 Correct 0 ms 87572 KB Output is correct
11 Correct 0 ms 87572 KB Output is correct
12 Correct 0 ms 87572 KB Output is correct
13 Correct 0 ms 87572 KB Output is correct
14 Correct 0 ms 87572 KB Output is correct
15 Correct 0 ms 87572 KB Output is correct
16 Correct 0 ms 87572 KB Output is correct
17 Correct 0 ms 87572 KB Output is correct
18 Correct 0 ms 87572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 87572 KB Output is correct
2 Correct 0 ms 87572 KB Output is correct
3 Correct 0 ms 87572 KB Output is correct
4 Correct 0 ms 87572 KB Output is correct
5 Correct 0 ms 87572 KB Output is correct
6 Correct 0 ms 87572 KB Output is correct
7 Correct 0 ms 87572 KB Output is correct
8 Correct 0 ms 87572 KB Output is correct
9 Correct 0 ms 87572 KB Output is correct
10 Correct 0 ms 87572 KB Output is correct
11 Correct 0 ms 87572 KB Output is correct
12 Correct 0 ms 87572 KB Output is correct
13 Correct 0 ms 87572 KB Output is correct
14 Correct 0 ms 87572 KB Output is correct
15 Correct 0 ms 87572 KB Output is correct
16 Correct 0 ms 87572 KB Output is correct
17 Correct 0 ms 87572 KB Output is correct
18 Correct 0 ms 87572 KB Output is correct
19 Correct 0 ms 87572 KB Output is correct
20 Correct 0 ms 87572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 87572 KB Output is correct
2 Correct 0 ms 87572 KB Output is correct
3 Correct 0 ms 87572 KB Output is correct
4 Correct 0 ms 87572 KB Output is correct
5 Correct 0 ms 87572 KB Output is correct
6 Correct 0 ms 87572 KB Output is correct
7 Correct 0 ms 87572 KB Output is correct
8 Correct 0 ms 87572 KB Output is correct
9 Correct 0 ms 87572 KB Output is correct
10 Correct 0 ms 87572 KB Output is correct
11 Correct 0 ms 87572 KB Output is correct
12 Correct 0 ms 87572 KB Output is correct
13 Correct 0 ms 87572 KB Output is correct
14 Correct 0 ms 87572 KB Output is correct
15 Correct 0 ms 87572 KB Output is correct
16 Correct 0 ms 87572 KB Output is correct
17 Correct 0 ms 87572 KB Output is correct
18 Correct 0 ms 87572 KB Output is correct
19 Correct 0 ms 87572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 87572 KB Output is correct
2 Correct 13 ms 87572 KB Output is correct
3 Correct 19 ms 87572 KB Output is correct
4 Correct 133 ms 87572 KB Output is correct
5 Correct 459 ms 87572 KB Output is correct
6 Correct 26 ms 87572 KB Output is correct
7 Correct 253 ms 87572 KB Output is correct
8 Correct 0 ms 87572 KB Output is correct
9 Correct 0 ms 87572 KB Output is correct
10 Correct 0 ms 87572 KB Output is correct
11 Correct 0 ms 87572 KB Output is correct
12 Correct 0 ms 87572 KB Output is correct
13 Correct 0 ms 87572 KB Output is correct
14 Correct 36 ms 87572 KB Output is correct
15 Correct 3 ms 87572 KB Output is correct
16 Correct 6 ms 87572 KB Output is correct
17 Correct 16 ms 87572 KB Output is correct
18 Correct 16 ms 87572 KB Output is correct
19 Correct 113 ms 87572 KB Output is correct
20 Correct 336 ms 87572 KB Output is correct
21 Correct 26 ms 87572 KB Output is correct
22 Correct 183 ms 87572 KB Output is correct
23 Correct 26 ms 87572 KB Output is correct
24 Correct 46 ms 87572 KB Output is correct
25 Correct 369 ms 87572 KB Output is correct
26 Correct 0 ms 87572 KB Output is correct
27 Correct 0 ms 87572 KB Output is correct
28 Correct 53 ms 87572 KB Output is correct
29 Correct 6 ms 87572 KB Output is correct
30 Correct 9 ms 87572 KB Output is correct
31 Correct 13 ms 87572 KB Output is correct
32 Correct 23 ms 87704 KB Output is correct
33 Correct 156 ms 87704 KB Output is correct
34 Correct 693 ms 87832 KB Output is correct
35 Correct 29 ms 87832 KB Output is correct
36 Correct 299 ms 87832 KB Output is correct
37 Correct 0 ms 87572 KB Output is correct
38 Correct 36 ms 87572 KB Output is correct
39 Correct 0 ms 87572 KB Output is correct
40 Correct 0 ms 87572 KB Output is correct
41 Correct 0 ms 87572 KB Output is correct
42 Correct 0 ms 87572 KB Output is correct