답안 #87312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
87312 2018-11-30T09:44:05 Z 7Polygonz K개의 묶음 (IZhO14_blocks) C++11
100 / 100
426 ms 43324 KB
using namespace std ;
#include <bits/stdc++.h> /* #7th-Polygon */
typedef pair < int , int > IntInt ;

const int N = 1e5 + 7 ;
const int K = 100 + 7 ;

unsigned int n , k , a[N] , dp[N][K] ;

int main()
{
    ios::sync_with_stdio(false) ;
    cout.tie(nullptr) ;
    cin.tie(nullptr) ;

    cin >> n >> k ;
    for (int i = 1 ; i <= n ; ++i)
        cin >> a[i] ;

    memset(dp , -1 , sizeof(dp)) ;

    dp[0][1] = 0 ;
    for (int i = 1 ; i <= n ; ++i)
        dp[i][1] = max(dp[i - 1][1] , a[i]) ;

    for (int b = 2 ; b <= k ; ++b)
    {
        stack < IntInt > my_stack ;
        for (int i = b ; i <= n ; ++i)
        {
            int min_dp = dp[i - 1][b - 1] ;
            for ( ; my_stack.size() ; my_stack.pop())
            {
                if (a[my_stack.top().first] > a[i]) break ;
                min_dp = min(min_dp , my_stack.top().second) ;
            }

            dp[i][b] = min(min_dp + a[i] , dp[my_stack.size() ? my_stack.top().first : 0][b]) ;
            my_stack.emplace(i , min_dp) ;
        }
    }

    cout << dp[n][k] << "\n" ;
    return 0 ;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:17:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1 ; i <= n ; ++i)
                      ~~^~~~
blocks.cpp:23:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1 ; i <= n ; ++i)
                      ~~^~~~
blocks.cpp:26:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int b = 2 ; b <= k ; ++b)
                      ~~^~~~
blocks.cpp:29:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = b ; i <= n ; ++i)
                          ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 42232 KB Output is correct
2 Correct 38 ms 42356 KB Output is correct
3 Correct 38 ms 42356 KB Output is correct
4 Correct 37 ms 42356 KB Output is correct
5 Correct 38 ms 42428 KB Output is correct
6 Correct 37 ms 42460 KB Output is correct
7 Correct 37 ms 42460 KB Output is correct
8 Correct 38 ms 42460 KB Output is correct
9 Correct 37 ms 42460 KB Output is correct
10 Correct 37 ms 42572 KB Output is correct
11 Correct 38 ms 42572 KB Output is correct
12 Correct 37 ms 42572 KB Output is correct
13 Correct 37 ms 42572 KB Output is correct
14 Correct 36 ms 42572 KB Output is correct
15 Correct 43 ms 42572 KB Output is correct
16 Correct 36 ms 42572 KB Output is correct
17 Correct 36 ms 42572 KB Output is correct
18 Correct 36 ms 42572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 42572 KB Output is correct
2 Correct 36 ms 42572 KB Output is correct
3 Correct 37 ms 42572 KB Output is correct
4 Correct 38 ms 42572 KB Output is correct
5 Correct 36 ms 42572 KB Output is correct
6 Correct 37 ms 42572 KB Output is correct
7 Correct 39 ms 42572 KB Output is correct
8 Correct 36 ms 42572 KB Output is correct
9 Correct 37 ms 42572 KB Output is correct
10 Correct 36 ms 42572 KB Output is correct
11 Correct 38 ms 42572 KB Output is correct
12 Correct 36 ms 42572 KB Output is correct
13 Correct 36 ms 42572 KB Output is correct
14 Correct 37 ms 42572 KB Output is correct
15 Correct 36 ms 42572 KB Output is correct
16 Correct 36 ms 42584 KB Output is correct
17 Correct 37 ms 42584 KB Output is correct
18 Correct 38 ms 42584 KB Output is correct
19 Correct 38 ms 42584 KB Output is correct
20 Correct 36 ms 42584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 42620 KB Output is correct
2 Correct 36 ms 42620 KB Output is correct
3 Correct 37 ms 42620 KB Output is correct
4 Correct 36 ms 42620 KB Output is correct
5 Correct 36 ms 42620 KB Output is correct
6 Correct 37 ms 42620 KB Output is correct
7 Correct 36 ms 42620 KB Output is correct
8 Correct 37 ms 42620 KB Output is correct
9 Correct 37 ms 42620 KB Output is correct
10 Correct 38 ms 42620 KB Output is correct
11 Correct 38 ms 42620 KB Output is correct
12 Correct 36 ms 42620 KB Output is correct
13 Correct 38 ms 42620 KB Output is correct
14 Correct 36 ms 42620 KB Output is correct
15 Correct 36 ms 42620 KB Output is correct
16 Correct 37 ms 42620 KB Output is correct
17 Correct 38 ms 42620 KB Output is correct
18 Correct 37 ms 42620 KB Output is correct
19 Correct 36 ms 42620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 42620 KB Output is correct
2 Correct 42 ms 42668 KB Output is correct
3 Correct 46 ms 42668 KB Output is correct
4 Correct 102 ms 42788 KB Output is correct
5 Correct 258 ms 42916 KB Output is correct
6 Correct 51 ms 42916 KB Output is correct
7 Correct 137 ms 42916 KB Output is correct
8 Correct 36 ms 42916 KB Output is correct
9 Correct 37 ms 42916 KB Output is correct
10 Correct 37 ms 42916 KB Output is correct
11 Correct 36 ms 42916 KB Output is correct
12 Correct 37 ms 42916 KB Output is correct
13 Correct 38 ms 42916 KB Output is correct
14 Correct 56 ms 42916 KB Output is correct
15 Correct 38 ms 42916 KB Output is correct
16 Correct 44 ms 42916 KB Output is correct
17 Correct 43 ms 42916 KB Output is correct
18 Correct 48 ms 42916 KB Output is correct
19 Correct 108 ms 42916 KB Output is correct
20 Correct 313 ms 43004 KB Output is correct
21 Correct 53 ms 43004 KB Output is correct
22 Correct 174 ms 43004 KB Output is correct
23 Correct 48 ms 43004 KB Output is correct
24 Correct 73 ms 43004 KB Output is correct
25 Correct 323 ms 43004 KB Output is correct
26 Correct 37 ms 43004 KB Output is correct
27 Correct 36 ms 43004 KB Output is correct
28 Correct 53 ms 43004 KB Output is correct
29 Correct 39 ms 43004 KB Output is correct
30 Correct 43 ms 43004 KB Output is correct
31 Correct 41 ms 43004 KB Output is correct
32 Correct 50 ms 43004 KB Output is correct
33 Correct 102 ms 43004 KB Output is correct
34 Correct 426 ms 43312 KB Output is correct
35 Correct 55 ms 43312 KB Output is correct
36 Correct 189 ms 43324 KB Output is correct
37 Correct 38 ms 43324 KB Output is correct
38 Correct 54 ms 43324 KB Output is correct
39 Correct 46 ms 43324 KB Output is correct
40 Correct 38 ms 43324 KB Output is correct
41 Correct 37 ms 43324 KB Output is correct
42 Correct 37 ms 43324 KB Output is correct