답안 #922570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922570 2024-02-05T16:53:30 Z phong K개의 묶음 (IZhO14_blocks) C++17
100 / 100
355 ms 168408 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 1e5 + 5;
const ll oo = 1e18, base = 311;
const int lg = 19, M = 105;
const ll mod = 1e9 + 7;
#define pii pair<ll, int>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
using namespace std;

int n, k;
ll f[nmax][M], a[nmax], mi[nmax][M], h[nmax], b[nmax];
void ckmax(ll &a, ll b){
    a = max(a, b);
}
void ckmin(ll &a, ll b){
    a = min(a, b);
}
deque<int> de;
multiset<pii> mt;
int L[nmax];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.out", "w", stdout);
    cin >> n >> k;
    memset(f, 0x3f, sizeof f);
    memset(mi, 0x3f, sizeof f);

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        if(i == 1) f[1][1] = a[i];
        else f[i][1] = max(f[i - 1][1], a[i]);
    }
    h[0] = oo;
    for(int j = 1; j <= k; ++j){
        de.clear();mt.clear();
        for(int i = 1; i <= n; ++i){
            b[i] = mi[i][j - 1] + a[i];
        }
        for(int i = 1; i <= n; ++i){
            if(j > 1){
                while(de.size() && a[de.back()] <= a[i]){
                    h[de.size()] = oo;
                    de.pop_back();
                }
                int x = de.size();
                h[x + 1] = min(h[x], b[i]);
                de.push_back(i);
                f[i][j] = h[de.size()];
            }
            L[i] = i - 1;
            mi[i][j] = f[i - 1][j];
            while(L[i] && a[L[i]] <= a[i]){
                ckmin(mi[i][j],mi[L[i]][j]);
                L[i] = L[L[i]];
            }
        }
    }
    cout << f[n][k];

}
/*
5 2
1 2 3 4 5


*/

Compilation message

blocks.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 167396 KB Output is correct
2 Correct 23 ms 167344 KB Output is correct
3 Correct 22 ms 167260 KB Output is correct
4 Correct 23 ms 167352 KB Output is correct
5 Correct 23 ms 167260 KB Output is correct
6 Correct 23 ms 167260 KB Output is correct
7 Correct 23 ms 167248 KB Output is correct
8 Correct 22 ms 167304 KB Output is correct
9 Correct 23 ms 167388 KB Output is correct
10 Correct 22 ms 167356 KB Output is correct
11 Correct 22 ms 167260 KB Output is correct
12 Correct 23 ms 167256 KB Output is correct
13 Correct 23 ms 167248 KB Output is correct
14 Correct 23 ms 167260 KB Output is correct
15 Correct 23 ms 167248 KB Output is correct
16 Correct 24 ms 167276 KB Output is correct
17 Correct 24 ms 167512 KB Output is correct
18 Correct 23 ms 167260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 167260 KB Output is correct
2 Correct 22 ms 167364 KB Output is correct
3 Correct 23 ms 167252 KB Output is correct
4 Correct 24 ms 167256 KB Output is correct
5 Correct 22 ms 167280 KB Output is correct
6 Correct 23 ms 167260 KB Output is correct
7 Correct 22 ms 167392 KB Output is correct
8 Correct 24 ms 167388 KB Output is correct
9 Correct 23 ms 167328 KB Output is correct
10 Correct 23 ms 167336 KB Output is correct
11 Correct 24 ms 167252 KB Output is correct
12 Correct 24 ms 167332 KB Output is correct
13 Correct 22 ms 167260 KB Output is correct
14 Correct 24 ms 167176 KB Output is correct
15 Correct 22 ms 167316 KB Output is correct
16 Correct 23 ms 167216 KB Output is correct
17 Correct 23 ms 167260 KB Output is correct
18 Correct 23 ms 167252 KB Output is correct
19 Correct 23 ms 167260 KB Output is correct
20 Correct 22 ms 167260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 167396 KB Output is correct
2 Correct 23 ms 167344 KB Output is correct
3 Correct 22 ms 167260 KB Output is correct
4 Correct 23 ms 167352 KB Output is correct
5 Correct 23 ms 167260 KB Output is correct
6 Correct 23 ms 167260 KB Output is correct
7 Correct 23 ms 167248 KB Output is correct
8 Correct 22 ms 167304 KB Output is correct
9 Correct 23 ms 167388 KB Output is correct
10 Correct 22 ms 167356 KB Output is correct
11 Correct 22 ms 167260 KB Output is correct
12 Correct 23 ms 167256 KB Output is correct
13 Correct 23 ms 167248 KB Output is correct
14 Correct 23 ms 167260 KB Output is correct
15 Correct 23 ms 167248 KB Output is correct
16 Correct 24 ms 167276 KB Output is correct
17 Correct 24 ms 167512 KB Output is correct
18 Correct 23 ms 167260 KB Output is correct
19 Correct 23 ms 167260 KB Output is correct
20 Correct 22 ms 167364 KB Output is correct
21 Correct 23 ms 167252 KB Output is correct
22 Correct 24 ms 167256 KB Output is correct
23 Correct 22 ms 167280 KB Output is correct
24 Correct 23 ms 167260 KB Output is correct
25 Correct 22 ms 167392 KB Output is correct
26 Correct 24 ms 167388 KB Output is correct
27 Correct 23 ms 167328 KB Output is correct
28 Correct 23 ms 167336 KB Output is correct
29 Correct 24 ms 167252 KB Output is correct
30 Correct 24 ms 167332 KB Output is correct
31 Correct 22 ms 167260 KB Output is correct
32 Correct 24 ms 167176 KB Output is correct
33 Correct 22 ms 167316 KB Output is correct
34 Correct 23 ms 167216 KB Output is correct
35 Correct 23 ms 167260 KB Output is correct
36 Correct 23 ms 167252 KB Output is correct
37 Correct 23 ms 167260 KB Output is correct
38 Correct 22 ms 167260 KB Output is correct
39 Correct 23 ms 167268 KB Output is correct
40 Correct 24 ms 167232 KB Output is correct
41 Correct 24 ms 167376 KB Output is correct
42 Correct 24 ms 167248 KB Output is correct
43 Correct 24 ms 167608 KB Output is correct
44 Correct 23 ms 167252 KB Output is correct
45 Correct 26 ms 167204 KB Output is correct
46 Correct 23 ms 167260 KB Output is correct
47 Correct 23 ms 167248 KB Output is correct
48 Correct 34 ms 167248 KB Output is correct
49 Correct 26 ms 167256 KB Output is correct
50 Correct 27 ms 167248 KB Output is correct
51 Correct 24 ms 167256 KB Output is correct
52 Correct 25 ms 167256 KB Output is correct
53 Correct 26 ms 167260 KB Output is correct
54 Correct 24 ms 167260 KB Output is correct
55 Correct 23 ms 167404 KB Output is correct
56 Correct 23 ms 167260 KB Output is correct
57 Correct 24 ms 167260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 167396 KB Output is correct
2 Correct 23 ms 167344 KB Output is correct
3 Correct 22 ms 167260 KB Output is correct
4 Correct 23 ms 167352 KB Output is correct
5 Correct 23 ms 167260 KB Output is correct
6 Correct 23 ms 167260 KB Output is correct
7 Correct 23 ms 167248 KB Output is correct
8 Correct 22 ms 167304 KB Output is correct
9 Correct 23 ms 167388 KB Output is correct
10 Correct 22 ms 167356 KB Output is correct
11 Correct 22 ms 167260 KB Output is correct
12 Correct 23 ms 167256 KB Output is correct
13 Correct 23 ms 167248 KB Output is correct
14 Correct 23 ms 167260 KB Output is correct
15 Correct 23 ms 167248 KB Output is correct
16 Correct 24 ms 167276 KB Output is correct
17 Correct 24 ms 167512 KB Output is correct
18 Correct 23 ms 167260 KB Output is correct
19 Correct 23 ms 167260 KB Output is correct
20 Correct 22 ms 167364 KB Output is correct
21 Correct 23 ms 167252 KB Output is correct
22 Correct 24 ms 167256 KB Output is correct
23 Correct 22 ms 167280 KB Output is correct
24 Correct 23 ms 167260 KB Output is correct
25 Correct 22 ms 167392 KB Output is correct
26 Correct 24 ms 167388 KB Output is correct
27 Correct 23 ms 167328 KB Output is correct
28 Correct 23 ms 167336 KB Output is correct
29 Correct 24 ms 167252 KB Output is correct
30 Correct 24 ms 167332 KB Output is correct
31 Correct 22 ms 167260 KB Output is correct
32 Correct 24 ms 167176 KB Output is correct
33 Correct 22 ms 167316 KB Output is correct
34 Correct 23 ms 167216 KB Output is correct
35 Correct 23 ms 167260 KB Output is correct
36 Correct 23 ms 167252 KB Output is correct
37 Correct 23 ms 167260 KB Output is correct
38 Correct 22 ms 167260 KB Output is correct
39 Correct 23 ms 167268 KB Output is correct
40 Correct 24 ms 167232 KB Output is correct
41 Correct 24 ms 167376 KB Output is correct
42 Correct 24 ms 167248 KB Output is correct
43 Correct 24 ms 167608 KB Output is correct
44 Correct 23 ms 167252 KB Output is correct
45 Correct 26 ms 167204 KB Output is correct
46 Correct 23 ms 167260 KB Output is correct
47 Correct 23 ms 167248 KB Output is correct
48 Correct 34 ms 167248 KB Output is correct
49 Correct 26 ms 167256 KB Output is correct
50 Correct 27 ms 167248 KB Output is correct
51 Correct 24 ms 167256 KB Output is correct
52 Correct 25 ms 167256 KB Output is correct
53 Correct 26 ms 167260 KB Output is correct
54 Correct 24 ms 167260 KB Output is correct
55 Correct 23 ms 167404 KB Output is correct
56 Correct 23 ms 167260 KB Output is correct
57 Correct 24 ms 167260 KB Output is correct
58 Correct 29 ms 167388 KB Output is correct
59 Correct 27 ms 167760 KB Output is correct
60 Correct 35 ms 167764 KB Output is correct
61 Correct 90 ms 167820 KB Output is correct
62 Correct 269 ms 168252 KB Output is correct
63 Correct 38 ms 168252 KB Output is correct
64 Correct 154 ms 168260 KB Output is correct
65 Correct 33 ms 167248 KB Output is correct
66 Correct 39 ms 166992 KB Output is correct
67 Correct 55 ms 167212 KB Output is correct
68 Correct 25 ms 167356 KB Output is correct
69 Correct 31 ms 167260 KB Output is correct
70 Correct 31 ms 167260 KB Output is correct
71 Correct 56 ms 167504 KB Output is correct
72 Correct 25 ms 167256 KB Output is correct
73 Correct 38 ms 167256 KB Output is correct
74 Correct 36 ms 167744 KB Output is correct
75 Correct 33 ms 167652 KB Output is correct
76 Correct 107 ms 167844 KB Output is correct
77 Correct 355 ms 168244 KB Output is correct
78 Correct 39 ms 168028 KB Output is correct
79 Correct 156 ms 168020 KB Output is correct
80 Correct 49 ms 168068 KB Output is correct
81 Correct 67 ms 168252 KB Output is correct
82 Correct 277 ms 168252 KB Output is correct
83 Correct 23 ms 167296 KB Output is correct
84 Correct 31 ms 167272 KB Output is correct
85 Correct 51 ms 167512 KB Output is correct
86 Correct 32 ms 167484 KB Output is correct
87 Correct 33 ms 167296 KB Output is correct
88 Correct 32 ms 167772 KB Output is correct
89 Correct 39 ms 167764 KB Output is correct
90 Correct 102 ms 167948 KB Output is correct
91 Correct 312 ms 168408 KB Output is correct
92 Correct 37 ms 168396 KB Output is correct
93 Correct 141 ms 168404 KB Output is correct
94 Correct 26 ms 167396 KB Output is correct
95 Correct 48 ms 167512 KB Output is correct
96 Correct 30 ms 167252 KB Output is correct
97 Correct 28 ms 167260 KB Output is correct
98 Correct 23 ms 167344 KB Output is correct
99 Correct 24 ms 167252 KB Output is correct