답안 #386460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386460 2021-04-06T15:33:47 Z cpp219 K개의 묶음 (IZhO14_blocks) C++14
100 / 100
264 ms 41476 KB
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e5 + 6;
const ll Log2 = 19;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;

ll n,k,a[N],dp[N][101],mn[N],MaxSeg[N],L[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>k;
    for (ll i = 1;i <= n;i++) cin>>a[i];
    for (ll i = 0;i <= n;i++)
        for (ll j = 0;j <= k;j++) dp[i][j] = inf;
    ll curmax = 0;
    for (ll i = 1;i <= n;i++) curmax = max(curmax,a[i]),dp[i][1] = curmax;
    for (ll j = 2;j <= k;j++){
        stack<LL> st; /// first = minval    second = index
        for (ll i = j;i <= n;i++){
            ll now = dp[i - 1][j - 1];
            while(!st.empty() && a[st.top().sc] <= a[i]) now = min(now,st.top().fs),st.pop();
            dp[i][j] = now + a[i];
            if (st.size()) dp[i][j] = min(dp[i][j],dp[st.top().sc][j]);
            st.push({now,i});
        }
    }
    cout<<dp[n][k];
}

Compilation message

blocks.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
blocks.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
blocks.cpp:13:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000000000008e+16' to '2147483647' [-Woverflow]
   13 | const ll inf = 1e16 + 7;
      |                ~~~~~^~~
blocks.cpp: In function 'int main()':
blocks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 236 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 236 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 2 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 2 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 236 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 2 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 2 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 2 ms 364 KB Output is correct
58 Correct 8 ms 4460 KB Output is correct
59 Correct 14 ms 18540 KB Output is correct
60 Correct 18 ms 18412 KB Output is correct
61 Correct 65 ms 18412 KB Output is correct
62 Correct 213 ms 40940 KB Output is correct
63 Correct 33 ms 40940 KB Output is correct
64 Correct 109 ms 41068 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 2 ms 364 KB Output is correct
67 Correct 2 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 748 KB Output is correct
70 Correct 2 ms 748 KB Output is correct
71 Correct 23 ms 4460 KB Output is correct
72 Correct 4 ms 4460 KB Output is correct
73 Correct 9 ms 4460 KB Output is correct
74 Correct 14 ms 18412 KB Output is correct
75 Correct 19 ms 18412 KB Output is correct
76 Correct 85 ms 18412 KB Output is correct
77 Correct 264 ms 40940 KB Output is correct
78 Correct 34 ms 40940 KB Output is correct
79 Correct 134 ms 41068 KB Output is correct
80 Correct 30 ms 40940 KB Output is correct
81 Correct 51 ms 41068 KB Output is correct
82 Correct 258 ms 41016 KB Output is correct
83 Correct 1 ms 748 KB Output is correct
84 Correct 2 ms 748 KB Output is correct
85 Correct 21 ms 4460 KB Output is correct
86 Correct 4 ms 4460 KB Output is correct
87 Correct 8 ms 4460 KB Output is correct
88 Correct 14 ms 18412 KB Output is correct
89 Correct 19 ms 18668 KB Output is correct
90 Correct 72 ms 18668 KB Output is correct
91 Correct 246 ms 41476 KB Output is correct
92 Correct 41 ms 41300 KB Output is correct
93 Correct 124 ms 41364 KB Output is correct
94 Correct 4 ms 4460 KB Output is correct
95 Correct 19 ms 4460 KB Output is correct
96 Correct 1 ms 748 KB Output is correct
97 Correct 2 ms 748 KB Output is correct
98 Correct 2 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct