Submission #87313

# Submission time Handle Problem Language Result Execution time Memory
87313 2018-11-30T09:52:19 Z 7Polygonz K blocks (IZhO14_blocks) C++11
100 / 100
286 ms 43220 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 ;
const int INF = 1e9 + 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] ;

    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] , my_stack.size() ? dp[my_stack.top().first][b] : INF) ;
            my_stack.emplace(i , min_dp) ;
        }
    }

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

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:18:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1 ; i <= n ; ++i)
                      ~~^~~~
blocks.cpp:21: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 b = 2 ; b <= k ; ++b)
                      ~~^~~~
blocks.cpp:26:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = b ; i <= n ; ++i)
                          ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 456 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 2 ms 516 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4860 KB Output is correct
2 Correct 20 ms 19324 KB Output is correct
3 Correct 26 ms 19324 KB Output is correct
4 Correct 85 ms 19452 KB Output is correct
5 Correct 255 ms 43004 KB Output is correct
6 Correct 50 ms 43004 KB Output is correct
7 Correct 146 ms 43004 KB Output is correct
8 Correct 2 ms 43004 KB Output is correct
9 Correct 2 ms 43004 KB Output is correct
10 Correct 2 ms 43004 KB Output is correct
11 Correct 3 ms 43004 KB Output is correct
12 Correct 3 ms 43004 KB Output is correct
13 Correct 3 ms 43004 KB Output is correct
14 Correct 25 ms 43004 KB Output is correct
15 Correct 6 ms 43004 KB Output is correct
16 Correct 10 ms 43004 KB Output is correct
17 Correct 20 ms 43004 KB Output is correct
18 Correct 28 ms 43004 KB Output is correct
19 Correct 93 ms 43004 KB Output is correct
20 Correct 272 ms 43004 KB Output is correct
21 Correct 50 ms 43004 KB Output is correct
22 Correct 146 ms 43004 KB Output is correct
23 Correct 44 ms 43004 KB Output is correct
24 Correct 66 ms 43004 KB Output is correct
25 Correct 256 ms 43004 KB Output is correct
26 Correct 2 ms 43004 KB Output is correct
27 Correct 2 ms 43004 KB Output is correct
28 Correct 22 ms 43004 KB Output is correct
29 Correct 6 ms 43004 KB Output is correct
30 Correct 9 ms 43004 KB Output is correct
31 Correct 20 ms 43004 KB Output is correct
32 Correct 32 ms 43004 KB Output is correct
33 Correct 86 ms 43004 KB Output is correct
34 Correct 286 ms 43200 KB Output is correct
35 Correct 50 ms 43220 KB Output is correct
36 Correct 145 ms 43220 KB Output is correct
37 Correct 6 ms 43220 KB Output is correct
38 Correct 21 ms 43220 KB Output is correct
39 Correct 2 ms 43220 KB Output is correct
40 Correct 2 ms 43220 KB Output is correct
41 Correct 2 ms 43220 KB Output is correct
42 Correct 2 ms 43220 KB Output is correct