Submission #647686

# Submission time Handle Problem Language Result Execution time Memory
647686 2022-10-03T15:36:54 Z sugartheanh K blocks (IZhO14_blocks) C++14
100 / 100
306 ms 165916 KB
#include <bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define fi first
#define se second
#define oo 1e18
#define bit(x,i) (((x)>>(i))&1)
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int K = 1e2 + 5;
int n,k,a[N];
ll dp[K][N],f[K][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    fo(i,1,n)
        cin>>a[i];
    memset(dp,0x3f,sizeof(dp));
    memset(f,0x3f,sizeof(f));
    dp[0][0] = 0;
    a[0] = 1e9;
    fo(i,1,k)
    {
        stack<int>st;
        st.push(0);
        int mx = 0;
        fo(j,1,n)
        {
            mx = max(mx, a[j]);
            if(i == 1)
                dp[i][j] = f[i][j] = mx;
            ll tmp = 1e18;
            while(!st.empty() && a[st.top()] <= a[j])
            {
                int last = st.top();
                st.pop();
                f[i-1][st.top()] = min(f[i-1][st.top()], f[i-1][last]);
            }
            if(i <= j)
            {
                dp[i][j] = min({dp[i][j], dp[i][st.top()], f[i-1][st.top()] + a[j]});
                f[i][j] = dp[i][j];
            }
            st.push(j);
        }
    }
    cout<<dp[k][n];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:38:16: warning: unused variable 'tmp' [-Wunused-variable]
   38 |             ll tmp = 1e18;
      |                ^~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 164684 KB Output is correct
2 Correct 61 ms 164684 KB Output is correct
3 Correct 65 ms 164592 KB Output is correct
4 Correct 65 ms 164672 KB Output is correct
5 Correct 60 ms 164684 KB Output is correct
6 Correct 62 ms 164644 KB Output is correct
7 Correct 65 ms 164692 KB Output is correct
8 Correct 65 ms 164576 KB Output is correct
9 Correct 65 ms 164692 KB Output is correct
10 Correct 70 ms 164624 KB Output is correct
11 Correct 63 ms 164624 KB Output is correct
12 Correct 64 ms 164596 KB Output is correct
13 Correct 67 ms 164684 KB Output is correct
14 Correct 63 ms 164660 KB Output is correct
15 Correct 64 ms 164648 KB Output is correct
16 Correct 65 ms 164672 KB Output is correct
17 Correct 65 ms 164668 KB Output is correct
18 Correct 62 ms 164684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 164580 KB Output is correct
2 Correct 70 ms 164632 KB Output is correct
3 Correct 65 ms 164644 KB Output is correct
4 Correct 66 ms 164732 KB Output is correct
5 Correct 64 ms 164612 KB Output is correct
6 Correct 62 ms 164620 KB Output is correct
7 Correct 66 ms 164684 KB Output is correct
8 Correct 63 ms 164608 KB Output is correct
9 Correct 65 ms 164616 KB Output is correct
10 Correct 65 ms 164596 KB Output is correct
11 Correct 64 ms 164704 KB Output is correct
12 Correct 64 ms 164672 KB Output is correct
13 Correct 64 ms 164696 KB Output is correct
14 Correct 64 ms 164664 KB Output is correct
15 Correct 64 ms 164672 KB Output is correct
16 Correct 63 ms 164612 KB Output is correct
17 Correct 64 ms 164624 KB Output is correct
18 Correct 63 ms 164676 KB Output is correct
19 Correct 68 ms 164632 KB Output is correct
20 Correct 63 ms 164660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 164684 KB Output is correct
2 Correct 61 ms 164684 KB Output is correct
3 Correct 65 ms 164592 KB Output is correct
4 Correct 65 ms 164672 KB Output is correct
5 Correct 60 ms 164684 KB Output is correct
6 Correct 62 ms 164644 KB Output is correct
7 Correct 65 ms 164692 KB Output is correct
8 Correct 65 ms 164576 KB Output is correct
9 Correct 65 ms 164692 KB Output is correct
10 Correct 70 ms 164624 KB Output is correct
11 Correct 63 ms 164624 KB Output is correct
12 Correct 64 ms 164596 KB Output is correct
13 Correct 67 ms 164684 KB Output is correct
14 Correct 63 ms 164660 KB Output is correct
15 Correct 64 ms 164648 KB Output is correct
16 Correct 65 ms 164672 KB Output is correct
17 Correct 65 ms 164668 KB Output is correct
18 Correct 62 ms 164684 KB Output is correct
19 Correct 67 ms 164580 KB Output is correct
20 Correct 70 ms 164632 KB Output is correct
21 Correct 65 ms 164644 KB Output is correct
22 Correct 66 ms 164732 KB Output is correct
23 Correct 64 ms 164612 KB Output is correct
24 Correct 62 ms 164620 KB Output is correct
25 Correct 66 ms 164684 KB Output is correct
26 Correct 63 ms 164608 KB Output is correct
27 Correct 65 ms 164616 KB Output is correct
28 Correct 65 ms 164596 KB Output is correct
29 Correct 64 ms 164704 KB Output is correct
30 Correct 64 ms 164672 KB Output is correct
31 Correct 64 ms 164696 KB Output is correct
32 Correct 64 ms 164664 KB Output is correct
33 Correct 64 ms 164672 KB Output is correct
34 Correct 63 ms 164612 KB Output is correct
35 Correct 64 ms 164624 KB Output is correct
36 Correct 63 ms 164676 KB Output is correct
37 Correct 68 ms 164632 KB Output is correct
38 Correct 63 ms 164660 KB Output is correct
39 Correct 67 ms 164812 KB Output is correct
40 Correct 68 ms 164660 KB Output is correct
41 Correct 62 ms 164684 KB Output is correct
42 Correct 63 ms 164616 KB Output is correct
43 Correct 64 ms 164616 KB Output is correct
44 Correct 68 ms 164800 KB Output is correct
45 Correct 68 ms 164644 KB Output is correct
46 Correct 65 ms 164588 KB Output is correct
47 Correct 68 ms 164688 KB Output is correct
48 Correct 64 ms 164580 KB Output is correct
49 Correct 66 ms 164736 KB Output is correct
50 Correct 64 ms 164608 KB Output is correct
51 Correct 65 ms 164640 KB Output is correct
52 Correct 62 ms 164636 KB Output is correct
53 Correct 63 ms 164688 KB Output is correct
54 Correct 63 ms 164692 KB Output is correct
55 Correct 69 ms 164592 KB Output is correct
56 Correct 68 ms 164624 KB Output is correct
57 Correct 68 ms 164688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 164684 KB Output is correct
2 Correct 61 ms 164684 KB Output is correct
3 Correct 65 ms 164592 KB Output is correct
4 Correct 65 ms 164672 KB Output is correct
5 Correct 60 ms 164684 KB Output is correct
6 Correct 62 ms 164644 KB Output is correct
7 Correct 65 ms 164692 KB Output is correct
8 Correct 65 ms 164576 KB Output is correct
9 Correct 65 ms 164692 KB Output is correct
10 Correct 70 ms 164624 KB Output is correct
11 Correct 63 ms 164624 KB Output is correct
12 Correct 64 ms 164596 KB Output is correct
13 Correct 67 ms 164684 KB Output is correct
14 Correct 63 ms 164660 KB Output is correct
15 Correct 64 ms 164648 KB Output is correct
16 Correct 65 ms 164672 KB Output is correct
17 Correct 65 ms 164668 KB Output is correct
18 Correct 62 ms 164684 KB Output is correct
19 Correct 67 ms 164580 KB Output is correct
20 Correct 70 ms 164632 KB Output is correct
21 Correct 65 ms 164644 KB Output is correct
22 Correct 66 ms 164732 KB Output is correct
23 Correct 64 ms 164612 KB Output is correct
24 Correct 62 ms 164620 KB Output is correct
25 Correct 66 ms 164684 KB Output is correct
26 Correct 63 ms 164608 KB Output is correct
27 Correct 65 ms 164616 KB Output is correct
28 Correct 65 ms 164596 KB Output is correct
29 Correct 64 ms 164704 KB Output is correct
30 Correct 64 ms 164672 KB Output is correct
31 Correct 64 ms 164696 KB Output is correct
32 Correct 64 ms 164664 KB Output is correct
33 Correct 64 ms 164672 KB Output is correct
34 Correct 63 ms 164612 KB Output is correct
35 Correct 64 ms 164624 KB Output is correct
36 Correct 63 ms 164676 KB Output is correct
37 Correct 68 ms 164632 KB Output is correct
38 Correct 63 ms 164660 KB Output is correct
39 Correct 67 ms 164812 KB Output is correct
40 Correct 68 ms 164660 KB Output is correct
41 Correct 62 ms 164684 KB Output is correct
42 Correct 63 ms 164616 KB Output is correct
43 Correct 64 ms 164616 KB Output is correct
44 Correct 68 ms 164800 KB Output is correct
45 Correct 68 ms 164644 KB Output is correct
46 Correct 65 ms 164588 KB Output is correct
47 Correct 68 ms 164688 KB Output is correct
48 Correct 64 ms 164580 KB Output is correct
49 Correct 66 ms 164736 KB Output is correct
50 Correct 64 ms 164608 KB Output is correct
51 Correct 65 ms 164640 KB Output is correct
52 Correct 62 ms 164636 KB Output is correct
53 Correct 63 ms 164688 KB Output is correct
54 Correct 63 ms 164692 KB Output is correct
55 Correct 69 ms 164592 KB Output is correct
56 Correct 68 ms 164624 KB Output is correct
57 Correct 68 ms 164688 KB Output is correct
58 Correct 68 ms 164708 KB Output is correct
59 Correct 66 ms 165108 KB Output is correct
60 Correct 75 ms 165140 KB Output is correct
61 Correct 138 ms 165068 KB Output is correct
62 Correct 239 ms 165704 KB Output is correct
63 Correct 79 ms 165684 KB Output is correct
64 Correct 157 ms 165776 KB Output is correct
65 Correct 62 ms 164688 KB Output is correct
66 Correct 64 ms 164688 KB Output is correct
67 Correct 65 ms 164696 KB Output is correct
68 Correct 61 ms 164624 KB Output is correct
69 Correct 67 ms 164604 KB Output is correct
70 Correct 66 ms 164696 KB Output is correct
71 Correct 87 ms 164772 KB Output is correct
72 Correct 65 ms 164792 KB Output is correct
73 Correct 84 ms 164812 KB Output is correct
74 Correct 72 ms 165072 KB Output is correct
75 Correct 81 ms 165100 KB Output is correct
76 Correct 143 ms 165168 KB Output is correct
77 Correct 301 ms 165708 KB Output is correct
78 Correct 78 ms 165716 KB Output is correct
79 Correct 172 ms 165868 KB Output is correct
80 Correct 75 ms 165668 KB Output is correct
81 Correct 97 ms 165772 KB Output is correct
82 Correct 306 ms 165856 KB Output is correct
83 Correct 64 ms 164596 KB Output is correct
84 Correct 67 ms 164684 KB Output is correct
85 Correct 84 ms 164844 KB Output is correct
86 Correct 64 ms 164824 KB Output is correct
87 Correct 67 ms 164952 KB Output is correct
88 Correct 67 ms 165204 KB Output is correct
89 Correct 77 ms 165336 KB Output is correct
90 Correct 128 ms 165296 KB Output is correct
91 Correct 235 ms 165916 KB Output is correct
92 Correct 78 ms 165812 KB Output is correct
93 Correct 149 ms 165916 KB Output is correct
94 Correct 63 ms 164708 KB Output is correct
95 Correct 82 ms 164760 KB Output is correct
96 Correct 69 ms 164620 KB Output is correct
97 Correct 65 ms 164688 KB Output is correct
98 Correct 66 ms 164624 KB Output is correct
99 Correct 63 ms 164684 KB Output is correct