Submission #1079023

# Submission time Handle Problem Language Result Execution time Memory
1079023 2024-08-28T09:30:14 Z beobuoibacky K blocks (IZhO14_blocks) C++14
100 / 100
237 ms 82304 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+210;
int dp[N][102], p[N];
int n, k;
int32_t main(){
    #define task "task"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    memset(dp, 63, sizeof dp);
    for(int i=1;i<=n;i++)cin >> p[i];
    for(int i=1;i<=n;i++){
      if(i==1) dp[i][1]=p[i];
      else dp[i][1]=max(dp[i-1][1],p[i]);
    }
    for(int j=2;j<=k;j++){
        stack<int> st;
        while(!st.empty()) st.pop();
        for(int i=1;i<=n;i++){
            while(st.size() and p[i]>=p[st.top()]){
                dp[i][j]=min(dp[i][j], min(dp[st.top()][j-1]+p[i], dp[st.top()][j]-p[st.top()]+p[i]));
               // cerr << dp[i][j] << " " << i << " " << j << " " << "\n";
               st.pop();
            }
            if(st.size()){
              dp[i][j]=min(min(dp[st.top()][j-1]+p[i], dp[st.top()][j]), dp[i][j]);
            }
            st.push(i);
        }
      }
      cout << dp[n][k];
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 43 ms 80212 KB Output is correct
2 Correct 33 ms 80380 KB Output is correct
3 Correct 35 ms 80264 KB Output is correct
4 Correct 32 ms 80980 KB Output is correct
5 Correct 35 ms 80932 KB Output is correct
6 Correct 34 ms 81020 KB Output is correct
7 Correct 47 ms 80840 KB Output is correct
8 Correct 33 ms 80984 KB Output is correct
9 Correct 34 ms 80980 KB Output is correct
10 Correct 31 ms 80980 KB Output is correct
11 Correct 36 ms 80900 KB Output is correct
12 Correct 38 ms 81040 KB Output is correct
13 Correct 38 ms 80980 KB Output is correct
14 Correct 45 ms 80980 KB Output is correct
15 Correct 45 ms 80828 KB Output is correct
16 Correct 37 ms 80972 KB Output is correct
17 Correct 31 ms 80988 KB Output is correct
18 Correct 33 ms 80980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 80976 KB Output is correct
2 Correct 35 ms 80984 KB Output is correct
3 Correct 38 ms 80252 KB Output is correct
4 Correct 33 ms 80212 KB Output is correct
5 Correct 40 ms 80212 KB Output is correct
6 Correct 36 ms 80208 KB Output is correct
7 Correct 36 ms 80212 KB Output is correct
8 Correct 34 ms 80212 KB Output is correct
9 Correct 36 ms 80212 KB Output is correct
10 Correct 35 ms 80476 KB Output is correct
11 Correct 39 ms 80212 KB Output is correct
12 Correct 42 ms 80248 KB Output is correct
13 Correct 34 ms 80268 KB Output is correct
14 Correct 37 ms 80388 KB Output is correct
15 Correct 40 ms 80208 KB Output is correct
16 Correct 48 ms 80216 KB Output is correct
17 Correct 35 ms 80212 KB Output is correct
18 Correct 33 ms 80980 KB Output is correct
19 Correct 32 ms 80984 KB Output is correct
20 Correct 42 ms 80976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 80212 KB Output is correct
2 Correct 33 ms 80380 KB Output is correct
3 Correct 35 ms 80264 KB Output is correct
4 Correct 32 ms 80980 KB Output is correct
5 Correct 35 ms 80932 KB Output is correct
6 Correct 34 ms 81020 KB Output is correct
7 Correct 47 ms 80840 KB Output is correct
8 Correct 33 ms 80984 KB Output is correct
9 Correct 34 ms 80980 KB Output is correct
10 Correct 31 ms 80980 KB Output is correct
11 Correct 36 ms 80900 KB Output is correct
12 Correct 38 ms 81040 KB Output is correct
13 Correct 38 ms 80980 KB Output is correct
14 Correct 45 ms 80980 KB Output is correct
15 Correct 45 ms 80828 KB Output is correct
16 Correct 37 ms 80972 KB Output is correct
17 Correct 31 ms 80988 KB Output is correct
18 Correct 33 ms 80980 KB Output is correct
19 Correct 37 ms 80976 KB Output is correct
20 Correct 35 ms 80984 KB Output is correct
21 Correct 38 ms 80252 KB Output is correct
22 Correct 33 ms 80212 KB Output is correct
23 Correct 40 ms 80212 KB Output is correct
24 Correct 36 ms 80208 KB Output is correct
25 Correct 36 ms 80212 KB Output is correct
26 Correct 34 ms 80212 KB Output is correct
27 Correct 36 ms 80212 KB Output is correct
28 Correct 35 ms 80476 KB Output is correct
29 Correct 39 ms 80212 KB Output is correct
30 Correct 42 ms 80248 KB Output is correct
31 Correct 34 ms 80268 KB Output is correct
32 Correct 37 ms 80388 KB Output is correct
33 Correct 40 ms 80208 KB Output is correct
34 Correct 48 ms 80216 KB Output is correct
35 Correct 35 ms 80212 KB Output is correct
36 Correct 33 ms 80980 KB Output is correct
37 Correct 32 ms 80984 KB Output is correct
38 Correct 42 ms 80976 KB Output is correct
39 Correct 35 ms 80980 KB Output is correct
40 Correct 36 ms 81040 KB Output is correct
41 Correct 37 ms 80988 KB Output is correct
42 Correct 39 ms 80848 KB Output is correct
43 Correct 46 ms 80840 KB Output is correct
44 Correct 44 ms 80980 KB Output is correct
45 Correct 35 ms 80980 KB Output is correct
46 Correct 38 ms 80984 KB Output is correct
47 Correct 34 ms 80980 KB Output is correct
48 Correct 35 ms 80976 KB Output is correct
49 Correct 45 ms 81040 KB Output is correct
50 Correct 32 ms 80924 KB Output is correct
51 Correct 46 ms 80892 KB Output is correct
52 Correct 32 ms 80972 KB Output is correct
53 Correct 32 ms 80988 KB Output is correct
54 Correct 33 ms 80980 KB Output is correct
55 Correct 45 ms 80896 KB Output is correct
56 Correct 42 ms 80980 KB Output is correct
57 Correct 37 ms 80984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 80212 KB Output is correct
2 Correct 33 ms 80380 KB Output is correct
3 Correct 35 ms 80264 KB Output is correct
4 Correct 32 ms 80980 KB Output is correct
5 Correct 35 ms 80932 KB Output is correct
6 Correct 34 ms 81020 KB Output is correct
7 Correct 47 ms 80840 KB Output is correct
8 Correct 33 ms 80984 KB Output is correct
9 Correct 34 ms 80980 KB Output is correct
10 Correct 31 ms 80980 KB Output is correct
11 Correct 36 ms 80900 KB Output is correct
12 Correct 38 ms 81040 KB Output is correct
13 Correct 38 ms 80980 KB Output is correct
14 Correct 45 ms 80980 KB Output is correct
15 Correct 45 ms 80828 KB Output is correct
16 Correct 37 ms 80972 KB Output is correct
17 Correct 31 ms 80988 KB Output is correct
18 Correct 33 ms 80980 KB Output is correct
19 Correct 37 ms 80976 KB Output is correct
20 Correct 35 ms 80984 KB Output is correct
21 Correct 38 ms 80252 KB Output is correct
22 Correct 33 ms 80212 KB Output is correct
23 Correct 40 ms 80212 KB Output is correct
24 Correct 36 ms 80208 KB Output is correct
25 Correct 36 ms 80212 KB Output is correct
26 Correct 34 ms 80212 KB Output is correct
27 Correct 36 ms 80212 KB Output is correct
28 Correct 35 ms 80476 KB Output is correct
29 Correct 39 ms 80212 KB Output is correct
30 Correct 42 ms 80248 KB Output is correct
31 Correct 34 ms 80268 KB Output is correct
32 Correct 37 ms 80388 KB Output is correct
33 Correct 40 ms 80208 KB Output is correct
34 Correct 48 ms 80216 KB Output is correct
35 Correct 35 ms 80212 KB Output is correct
36 Correct 33 ms 80980 KB Output is correct
37 Correct 32 ms 80984 KB Output is correct
38 Correct 42 ms 80976 KB Output is correct
39 Correct 35 ms 80980 KB Output is correct
40 Correct 36 ms 81040 KB Output is correct
41 Correct 37 ms 80988 KB Output is correct
42 Correct 39 ms 80848 KB Output is correct
43 Correct 46 ms 80840 KB Output is correct
44 Correct 44 ms 80980 KB Output is correct
45 Correct 35 ms 80980 KB Output is correct
46 Correct 38 ms 80984 KB Output is correct
47 Correct 34 ms 80980 KB Output is correct
48 Correct 35 ms 80976 KB Output is correct
49 Correct 45 ms 81040 KB Output is correct
50 Correct 32 ms 80924 KB Output is correct
51 Correct 46 ms 80892 KB Output is correct
52 Correct 32 ms 80972 KB Output is correct
53 Correct 32 ms 80988 KB Output is correct
54 Correct 33 ms 80980 KB Output is correct
55 Correct 45 ms 80896 KB Output is correct
56 Correct 42 ms 80980 KB Output is correct
57 Correct 37 ms 80984 KB Output is correct
58 Correct 42 ms 81148 KB Output is correct
59 Correct 47 ms 81488 KB Output is correct
60 Correct 39 ms 81488 KB Output is correct
61 Correct 80 ms 81348 KB Output is correct
62 Correct 157 ms 81816 KB Output is correct
63 Correct 44 ms 81744 KB Output is correct
64 Correct 88 ms 81912 KB Output is correct
65 Correct 40 ms 80984 KB Output is correct
66 Correct 33 ms 80976 KB Output is correct
67 Correct 32 ms 80976 KB Output is correct
68 Correct 31 ms 80976 KB Output is correct
69 Correct 34 ms 81052 KB Output is correct
70 Correct 38 ms 80828 KB Output is correct
71 Correct 50 ms 81044 KB Output is correct
72 Correct 37 ms 80988 KB Output is correct
73 Correct 42 ms 80980 KB Output is correct
74 Correct 41 ms 81496 KB Output is correct
75 Correct 44 ms 81488 KB Output is correct
76 Correct 113 ms 81488 KB Output is correct
77 Correct 204 ms 81908 KB Output is correct
78 Correct 56 ms 81892 KB Output is correct
79 Correct 119 ms 81748 KB Output is correct
80 Correct 44 ms 81852 KB Output is correct
81 Correct 57 ms 81764 KB Output is correct
82 Correct 237 ms 82000 KB Output is correct
83 Correct 45 ms 80308 KB Output is correct
84 Correct 36 ms 80468 KB Output is correct
85 Correct 50 ms 80484 KB Output is correct
86 Correct 53 ms 80468 KB Output is correct
87 Correct 40 ms 80424 KB Output is correct
88 Correct 35 ms 80984 KB Output is correct
89 Correct 47 ms 81488 KB Output is correct
90 Correct 74 ms 81492 KB Output is correct
91 Correct 176 ms 82304 KB Output is correct
92 Correct 42 ms 82104 KB Output is correct
93 Correct 105 ms 82204 KB Output is correct
94 Correct 31 ms 80976 KB Output is correct
95 Correct 44 ms 81204 KB Output is correct
96 Correct 38 ms 80976 KB Output is correct
97 Correct 32 ms 80976 KB Output is correct
98 Correct 34 ms 80988 KB Output is correct
99 Correct 32 ms 80980 KB Output is correct