답안 #228762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228762 2020-05-02T13:56:41 Z davitmarg K개의 묶음 (IZhO14_blocks) C++17
100 / 100
163 ms 167332 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 100005;

int n, k;
LL a[N], lst[N], dp[N][105], mindp[N][105];

vector<int> s;
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        scanf("%lld", a + i);

    a[0] = mod;
    s.PB(0);

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= k; j++)
            dp[i][j] = mindp[i][j] = mod * mod;
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++)
    {
        while (a[s.back()] <= a[i])
        {
            for (int j = 0; j <= k; j++)
                mindp[i][j] = min(mindp[i][j], min(mindp[s.back()][j], dp[s.back()][j]));
            s.pop_back();
        }
        lst[i] = s.back();
        for (int j = 0; j <= k; j++)
            mindp[i][j] = min(mindp[i][j], dp[lst[i]][j]);
        s.PB(i);

        for (int j = 1; j <= k; j++)
        {
            dp[i][j] = min(dp[i][j], dp[lst[i]][j]);
          /*  for (int x = i; x > lst[i]; x--)
                dp[i][j] = min(dp[i][j], dp[x - 1][j - 1] + a[i]);*/
            dp[i][j] = min(dp[i][j], mindp[i][j - 1] + a[i]);
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

/*

2 4
9 10
5 4 5 5


*/

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", a + i);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 436 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 17024 KB Output is correct
2 Correct 50 ms 74368 KB Output is correct
3 Correct 57 ms 74360 KB Output is correct
4 Correct 72 ms 74360 KB Output is correct
5 Correct 155 ms 166904 KB Output is correct
6 Correct 111 ms 166940 KB Output is correct
7 Correct 160 ms 166904 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 6 ms 2048 KB Output is correct
13 Correct 6 ms 2048 KB Output is correct
14 Correct 22 ms 17024 KB Output is correct
15 Correct 16 ms 17024 KB Output is correct
16 Correct 20 ms 17024 KB Output is correct
17 Correct 57 ms 74360 KB Output is correct
18 Correct 59 ms 74360 KB Output is correct
19 Correct 73 ms 74488 KB Output is correct
20 Correct 161 ms 166880 KB Output is correct
21 Correct 121 ms 166904 KB Output is correct
22 Correct 163 ms 167032 KB Output is correct
23 Correct 108 ms 166904 KB Output is correct
24 Correct 129 ms 167032 KB Output is correct
25 Correct 158 ms 166904 KB Output is correct
26 Correct 6 ms 2048 KB Output is correct
27 Correct 7 ms 2048 KB Output is correct
28 Correct 19 ms 17024 KB Output is correct
29 Correct 15 ms 17024 KB Output is correct
30 Correct 19 ms 17024 KB Output is correct
31 Correct 49 ms 74496 KB Output is correct
32 Correct 59 ms 74488 KB Output is correct
33 Correct 70 ms 74616 KB Output is correct
34 Correct 149 ms 167288 KB Output is correct
35 Correct 114 ms 167288 KB Output is correct
36 Correct 163 ms 167332 KB Output is correct
37 Correct 15 ms 17024 KB Output is correct
38 Correct 24 ms 17024 KB Output is correct
39 Correct 6 ms 2048 KB Output is correct
40 Correct 6 ms 2048 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct