답안 #872735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872735 2023-11-13T16:10:37 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++17
100 / 100
216 ms 82396 KB
#include <bits/stdc++.h>

#define FOR(i, l, r) for(int i = (l); i <= (r); i ++)
#define ll long long
#define MASK(j)  (1LL << (j))
#define int ll

using namespace std;

int f[100001][101];
int a[200000];

signed main() {
    if(fopen("blocks.in", "r")) {
        freopen("blocks.in", "r", stdin);
        freopen("blocks.out", "w", stdout);
    }

    if(fopen("a.inp", "r")) {
        freopen("a.inp", "r", stdin);
        freopen("a.out", "w", stdout);
    }

    int n, k;
    cin >> n >> k;

    FOR(i, 1, n) cin >> a[i];
    int mx = 0;
    FOR(i, 1, n) mx = max(mx, a[i]), f[i][1] = mx;

    FOR(j, 2, k){
        stack <pair <int,int>> q;
        FOR(i, j, n){
            ll minF = f[i - 1][j - 1];

            while(q.size() && a[q.top().first] <= a[i]){
                minF = min(minF, q.top().second);
                q.pop();
            }

            f[i][j] = minF + a[i];

            if(q.size())
                f[i][j] = min(f[i][j], q.top().second + a[q.top().first]),
                f[i][j] = min(f[i][j], f[q.top().first][j]);



            q.push({i, minF});
        }
    }

    cout << f[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("blocks.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen("blocks.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("a.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("a.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2496 KB Output is correct
16 Correct 1 ms 2496 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2484 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2500 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2496 KB Output is correct
16 Correct 1 ms 2496 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2484 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2500 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 0 ms 2496 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 0 ms 2496 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2392 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2496 KB Output is correct
16 Correct 1 ms 2496 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2484 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2500 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 0 ms 2496 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2392 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 0 ms 2496 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2496 KB Output is correct
58 Correct 6 ms 10840 KB Output is correct
59 Correct 14 ms 37724 KB Output is correct
60 Correct 17 ms 37800 KB Output is correct
61 Correct 61 ms 37724 KB Output is correct
62 Correct 216 ms 81548 KB Output is correct
63 Correct 35 ms 81492 KB Output is correct
64 Correct 117 ms 81488 KB Output is correct
65 Correct 0 ms 2392 KB Output is correct
66 Correct 1 ms 2396 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 0 ms 2396 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 4444 KB Output is correct
71 Correct 16 ms 10848 KB Output is correct
72 Correct 4 ms 10840 KB Output is correct
73 Correct 7 ms 10816 KB Output is correct
74 Correct 13 ms 37724 KB Output is correct
75 Correct 17 ms 37724 KB Output is correct
76 Correct 60 ms 37828 KB Output is correct
77 Correct 169 ms 81500 KB Output is correct
78 Correct 32 ms 81492 KB Output is correct
79 Correct 92 ms 81512 KB Output is correct
80 Correct 30 ms 81488 KB Output is correct
81 Correct 43 ms 81512 KB Output is correct
82 Correct 170 ms 81552 KB Output is correct
83 Correct 1 ms 4444 KB Output is correct
84 Correct 1 ms 4444 KB Output is correct
85 Correct 15 ms 10784 KB Output is correct
86 Correct 4 ms 10840 KB Output is correct
87 Correct 6 ms 10844 KB Output is correct
88 Correct 13 ms 37708 KB Output is correct
89 Correct 17 ms 38096 KB Output is correct
90 Correct 58 ms 38092 KB Output is correct
91 Correct 187 ms 82196 KB Output is correct
92 Correct 32 ms 82072 KB Output is correct
93 Correct 101 ms 82396 KB Output is correct
94 Correct 4 ms 10840 KB Output is correct
95 Correct 14 ms 10844 KB Output is correct
96 Correct 1 ms 4444 KB Output is correct
97 Correct 1 ms 4544 KB Output is correct
98 Correct 0 ms 2408 KB Output is correct
99 Correct 0 ms 2396 KB Output is correct