답안 #168768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168768 2019-12-16T04:57:24 Z NHDanDz K개의 묶음 (IZhO14_blocks) C++14
100 / 100
275 ms 84196 KB
/// NHDanDz
#include <bits/stdc++.h>
#define nmax 100005
#define F first
#define S second
#define PB push_back
#define PF push_front
#define ll long long
#define int ll
#define RyoLoveHentai "blocks"
#define pii pair<int,int>
#define reset(a) memset(a,0,sizeof(a))
using namespace std;
int n , k , a[nmax] , d[105][100005];
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    memset(d , 19 , sizeof(d));
    d[1][0] = 0;
    for(int i = 1; i <= n ; i++)
        d[1][i] = max(d[1][i - 1] , a[i]);
    for(int i = 2; i <= k; i++)
    {
        stack <pii> S;
        for(int j = i; j <= n; j++)
        {
            int MIN = d[i - 1][j - 1];
            //cout << MIN << " ";
            while(S.size() && a[S.top().S] <= a[j])
            {
                MIN = min(MIN , S.top().F);
                S.pop();
            }
            d[i][j] = min(d[i][S.size() ? S.top().S : 0] , MIN + a[j]);
            //cout << (S.size() ? S.top().S : 0) << " ";
            S.push({MIN , j});
        }
        //cout << endl;
    }
    cout << d[k][n];
}

Compilation message

blocks.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 82552 KB Output is correct
2 Correct 67 ms 82552 KB Output is correct
3 Correct 67 ms 82564 KB Output is correct
4 Correct 67 ms 82600 KB Output is correct
5 Correct 67 ms 82552 KB Output is correct
6 Correct 67 ms 82552 KB Output is correct
7 Correct 67 ms 82552 KB Output is correct
8 Correct 67 ms 82584 KB Output is correct
9 Correct 67 ms 82580 KB Output is correct
10 Correct 67 ms 82552 KB Output is correct
11 Correct 72 ms 82588 KB Output is correct
12 Correct 67 ms 82556 KB Output is correct
13 Correct 67 ms 82552 KB Output is correct
14 Correct 75 ms 82552 KB Output is correct
15 Correct 68 ms 82552 KB Output is correct
16 Correct 67 ms 82552 KB Output is correct
17 Correct 68 ms 82596 KB Output is correct
18 Correct 67 ms 82552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 82536 KB Output is correct
2 Correct 67 ms 82552 KB Output is correct
3 Correct 68 ms 82552 KB Output is correct
4 Correct 67 ms 82552 KB Output is correct
5 Correct 67 ms 82504 KB Output is correct
6 Correct 68 ms 82556 KB Output is correct
7 Correct 67 ms 82488 KB Output is correct
8 Correct 68 ms 82552 KB Output is correct
9 Correct 67 ms 82508 KB Output is correct
10 Correct 67 ms 82552 KB Output is correct
11 Correct 67 ms 82516 KB Output is correct
12 Correct 68 ms 82552 KB Output is correct
13 Correct 67 ms 82552 KB Output is correct
14 Correct 67 ms 82680 KB Output is correct
15 Correct 67 ms 82552 KB Output is correct
16 Correct 67 ms 82552 KB Output is correct
17 Correct 67 ms 82584 KB Output is correct
18 Correct 67 ms 82580 KB Output is correct
19 Correct 68 ms 82552 KB Output is correct
20 Correct 67 ms 82552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 82552 KB Output is correct
2 Correct 67 ms 82552 KB Output is correct
3 Correct 68 ms 82596 KB Output is correct
4 Correct 68 ms 82552 KB Output is correct
5 Correct 68 ms 82572 KB Output is correct
6 Correct 67 ms 82552 KB Output is correct
7 Correct 67 ms 82552 KB Output is correct
8 Correct 68 ms 82552 KB Output is correct
9 Correct 69 ms 82552 KB Output is correct
10 Correct 67 ms 82556 KB Output is correct
11 Correct 68 ms 82572 KB Output is correct
12 Correct 68 ms 82552 KB Output is correct
13 Correct 67 ms 82496 KB Output is correct
14 Correct 67 ms 82552 KB Output is correct
15 Correct 67 ms 82524 KB Output is correct
16 Correct 68 ms 82552 KB Output is correct
17 Correct 68 ms 82552 KB Output is correct
18 Correct 68 ms 82680 KB Output is correct
19 Correct 68 ms 82588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 82660 KB Output is correct
2 Correct 72 ms 82836 KB Output is correct
3 Correct 76 ms 83016 KB Output is correct
4 Correct 121 ms 82812 KB Output is correct
5 Correct 222 ms 83320 KB Output is correct
6 Correct 82 ms 83320 KB Output is correct
7 Correct 143 ms 83320 KB Output is correct
8 Correct 67 ms 82552 KB Output is correct
9 Correct 67 ms 82552 KB Output is correct
10 Correct 68 ms 82568 KB Output is correct
11 Correct 74 ms 82680 KB Output is correct
12 Correct 73 ms 82680 KB Output is correct
13 Correct 68 ms 82576 KB Output is correct
14 Correct 85 ms 82556 KB Output is correct
15 Correct 69 ms 82588 KB Output is correct
16 Correct 73 ms 82556 KB Output is correct
17 Correct 73 ms 82808 KB Output is correct
18 Correct 88 ms 82936 KB Output is correct
19 Correct 139 ms 83052 KB Output is correct
20 Correct 275 ms 83324 KB Output is correct
21 Correct 97 ms 83320 KB Output is correct
22 Correct 160 ms 83360 KB Output is correct
23 Correct 79 ms 83320 KB Output is correct
24 Correct 96 ms 83324 KB Output is correct
25 Correct 262 ms 83320 KB Output is correct
26 Correct 67 ms 82552 KB Output is correct
27 Correct 67 ms 82680 KB Output is correct
28 Correct 85 ms 82808 KB Output is correct
29 Correct 69 ms 82680 KB Output is correct
30 Correct 72 ms 82680 KB Output is correct
31 Correct 73 ms 82936 KB Output is correct
32 Correct 77 ms 83192 KB Output is correct
33 Correct 136 ms 83304 KB Output is correct
34 Correct 272 ms 84196 KB Output is correct
35 Correct 84 ms 83960 KB Output is correct
36 Correct 165 ms 83944 KB Output is correct
37 Correct 69 ms 82552 KB Output is correct
38 Correct 83 ms 82684 KB Output is correct
39 Correct 67 ms 82676 KB Output is correct
40 Correct 67 ms 82552 KB Output is correct
41 Correct 67 ms 82552 KB Output is correct
42 Correct 67 ms 82524 KB Output is correct