Submission #1077155

# Submission time Handle Problem Language Result Execution time Memory
1077155 2024-08-27T01:57:49 Z duyhoanho K blocks (IZhO14_blocks) C++17
100 / 100
210 ms 82048 KB
#include <bits/stdc++.h>
#define task ""
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+10;
int n,a[N],dp[N][102],k;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    if (fopen ("blocks.in", "r"))
    {
        freopen ("blocks.in", "r", stdin);
        freopen ("blocks.out", "w", stdout);
    }
    cin>>n>>k;
    memset(dp,99,sizeof dp);
    int mx=0;
    forinc(i,1,n)
    {
        cin>>a[i];
        mx=max(mx,a[i]);
        dp[i][1] = mx;

    }

    for(int j=2; j<=k; j++)
    {
        stack<int> st;
        for(int i=1; i<=n; i++)
        {
            while(st.size() && a[st.top()] <= a[i] )
            {
                dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]);
                dp[i][j] = min(dp[i][j],dp[st.top()][j] - a[st.top()] + a[i]);
                st.pop();
            }
            if(st.size())
            {
                dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]);
                dp[i][j] = min(dp[i][j],dp[st.top()][j]);
                dp[i][j] = min(dp[i][j] , dp[st.top() - 1][j - 1] + a[st.top()]);
            }
            st.push(i);
        }
    }
//    forinc(i,1,n)
//    {
//      forinc(j,1,k) cout<<dp[i][j]<<" ";
//      cout<<"\n";
//    }
    cout<<dp[n][k];
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:16:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen ("blocks.in", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:17:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen ("blocks.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 80124 KB Output is correct
2 Correct 39 ms 80208 KB Output is correct
3 Correct 39 ms 80212 KB Output is correct
4 Correct 46 ms 80208 KB Output is correct
5 Correct 43 ms 80212 KB Output is correct
6 Correct 39 ms 80216 KB Output is correct
7 Correct 38 ms 80220 KB Output is correct
8 Correct 39 ms 80220 KB Output is correct
9 Correct 37 ms 80260 KB Output is correct
10 Correct 36 ms 80160 KB Output is correct
11 Correct 46 ms 80212 KB Output is correct
12 Correct 45 ms 80156 KB Output is correct
13 Correct 43 ms 80212 KB Output is correct
14 Correct 50 ms 80208 KB Output is correct
15 Correct 36 ms 80208 KB Output is correct
16 Correct 40 ms 80216 KB Output is correct
17 Correct 40 ms 80120 KB Output is correct
18 Correct 39 ms 80212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 80268 KB Output is correct
2 Correct 37 ms 80220 KB Output is correct
3 Correct 38 ms 80212 KB Output is correct
4 Correct 39 ms 80208 KB Output is correct
5 Correct 36 ms 80212 KB Output is correct
6 Correct 40 ms 80104 KB Output is correct
7 Correct 36 ms 80312 KB Output is correct
8 Correct 38 ms 80220 KB Output is correct
9 Correct 39 ms 80464 KB Output is correct
10 Correct 46 ms 80208 KB Output is correct
11 Correct 48 ms 80208 KB Output is correct
12 Correct 39 ms 80060 KB Output is correct
13 Correct 40 ms 80272 KB Output is correct
14 Correct 48 ms 80212 KB Output is correct
15 Correct 44 ms 80212 KB Output is correct
16 Correct 38 ms 80212 KB Output is correct
17 Correct 39 ms 80208 KB Output is correct
18 Correct 38 ms 80292 KB Output is correct
19 Correct 41 ms 80036 KB Output is correct
20 Correct 38 ms 80208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 80124 KB Output is correct
2 Correct 39 ms 80208 KB Output is correct
3 Correct 39 ms 80212 KB Output is correct
4 Correct 46 ms 80208 KB Output is correct
5 Correct 43 ms 80212 KB Output is correct
6 Correct 39 ms 80216 KB Output is correct
7 Correct 38 ms 80220 KB Output is correct
8 Correct 39 ms 80220 KB Output is correct
9 Correct 37 ms 80260 KB Output is correct
10 Correct 36 ms 80160 KB Output is correct
11 Correct 46 ms 80212 KB Output is correct
12 Correct 45 ms 80156 KB Output is correct
13 Correct 43 ms 80212 KB Output is correct
14 Correct 50 ms 80208 KB Output is correct
15 Correct 36 ms 80208 KB Output is correct
16 Correct 40 ms 80216 KB Output is correct
17 Correct 40 ms 80120 KB Output is correct
18 Correct 39 ms 80212 KB Output is correct
19 Correct 39 ms 80268 KB Output is correct
20 Correct 37 ms 80220 KB Output is correct
21 Correct 38 ms 80212 KB Output is correct
22 Correct 39 ms 80208 KB Output is correct
23 Correct 36 ms 80212 KB Output is correct
24 Correct 40 ms 80104 KB Output is correct
25 Correct 36 ms 80312 KB Output is correct
26 Correct 38 ms 80220 KB Output is correct
27 Correct 39 ms 80464 KB Output is correct
28 Correct 46 ms 80208 KB Output is correct
29 Correct 48 ms 80208 KB Output is correct
30 Correct 39 ms 80060 KB Output is correct
31 Correct 40 ms 80272 KB Output is correct
32 Correct 48 ms 80212 KB Output is correct
33 Correct 44 ms 80212 KB Output is correct
34 Correct 38 ms 80212 KB Output is correct
35 Correct 39 ms 80208 KB Output is correct
36 Correct 38 ms 80292 KB Output is correct
37 Correct 41 ms 80036 KB Output is correct
38 Correct 38 ms 80208 KB Output is correct
39 Correct 39 ms 80208 KB Output is correct
40 Correct 37 ms 80252 KB Output is correct
41 Correct 43 ms 80208 KB Output is correct
42 Correct 37 ms 80216 KB Output is correct
43 Correct 39 ms 80112 KB Output is correct
44 Correct 36 ms 80208 KB Output is correct
45 Correct 38 ms 80212 KB Output is correct
46 Correct 41 ms 80208 KB Output is correct
47 Correct 39 ms 80216 KB Output is correct
48 Correct 36 ms 80208 KB Output is correct
49 Correct 37 ms 80220 KB Output is correct
50 Correct 48 ms 80212 KB Output is correct
51 Correct 39 ms 80212 KB Output is correct
52 Correct 41 ms 80212 KB Output is correct
53 Correct 38 ms 80096 KB Output is correct
54 Correct 38 ms 80212 KB Output is correct
55 Correct 43 ms 80208 KB Output is correct
56 Correct 48 ms 80208 KB Output is correct
57 Correct 36 ms 80208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 80124 KB Output is correct
2 Correct 39 ms 80208 KB Output is correct
3 Correct 39 ms 80212 KB Output is correct
4 Correct 46 ms 80208 KB Output is correct
5 Correct 43 ms 80212 KB Output is correct
6 Correct 39 ms 80216 KB Output is correct
7 Correct 38 ms 80220 KB Output is correct
8 Correct 39 ms 80220 KB Output is correct
9 Correct 37 ms 80260 KB Output is correct
10 Correct 36 ms 80160 KB Output is correct
11 Correct 46 ms 80212 KB Output is correct
12 Correct 45 ms 80156 KB Output is correct
13 Correct 43 ms 80212 KB Output is correct
14 Correct 50 ms 80208 KB Output is correct
15 Correct 36 ms 80208 KB Output is correct
16 Correct 40 ms 80216 KB Output is correct
17 Correct 40 ms 80120 KB Output is correct
18 Correct 39 ms 80212 KB Output is correct
19 Correct 39 ms 80268 KB Output is correct
20 Correct 37 ms 80220 KB Output is correct
21 Correct 38 ms 80212 KB Output is correct
22 Correct 39 ms 80208 KB Output is correct
23 Correct 36 ms 80212 KB Output is correct
24 Correct 40 ms 80104 KB Output is correct
25 Correct 36 ms 80312 KB Output is correct
26 Correct 38 ms 80220 KB Output is correct
27 Correct 39 ms 80464 KB Output is correct
28 Correct 46 ms 80208 KB Output is correct
29 Correct 48 ms 80208 KB Output is correct
30 Correct 39 ms 80060 KB Output is correct
31 Correct 40 ms 80272 KB Output is correct
32 Correct 48 ms 80212 KB Output is correct
33 Correct 44 ms 80212 KB Output is correct
34 Correct 38 ms 80212 KB Output is correct
35 Correct 39 ms 80208 KB Output is correct
36 Correct 38 ms 80292 KB Output is correct
37 Correct 41 ms 80036 KB Output is correct
38 Correct 38 ms 80208 KB Output is correct
39 Correct 39 ms 80208 KB Output is correct
40 Correct 37 ms 80252 KB Output is correct
41 Correct 43 ms 80208 KB Output is correct
42 Correct 37 ms 80216 KB Output is correct
43 Correct 39 ms 80112 KB Output is correct
44 Correct 36 ms 80208 KB Output is correct
45 Correct 38 ms 80212 KB Output is correct
46 Correct 41 ms 80208 KB Output is correct
47 Correct 39 ms 80216 KB Output is correct
48 Correct 36 ms 80208 KB Output is correct
49 Correct 37 ms 80220 KB Output is correct
50 Correct 48 ms 80212 KB Output is correct
51 Correct 39 ms 80212 KB Output is correct
52 Correct 41 ms 80212 KB Output is correct
53 Correct 38 ms 80096 KB Output is correct
54 Correct 38 ms 80212 KB Output is correct
55 Correct 43 ms 80208 KB Output is correct
56 Correct 48 ms 80208 KB Output is correct
57 Correct 36 ms 80208 KB Output is correct
58 Correct 41 ms 80244 KB Output is correct
59 Correct 42 ms 80720 KB Output is correct
60 Correct 41 ms 80720 KB Output is correct
61 Correct 75 ms 80732 KB Output is correct
62 Correct 153 ms 81748 KB Output is correct
63 Correct 46 ms 81560 KB Output is correct
64 Correct 90 ms 81760 KB Output is correct
65 Correct 39 ms 80216 KB Output is correct
66 Correct 36 ms 80100 KB Output is correct
67 Correct 49 ms 80208 KB Output is correct
68 Correct 34 ms 80212 KB Output is correct
69 Correct 34 ms 80204 KB Output is correct
70 Correct 54 ms 80288 KB Output is correct
71 Correct 49 ms 80208 KB Output is correct
72 Correct 38 ms 80208 KB Output is correct
73 Correct 43 ms 80364 KB Output is correct
74 Correct 37 ms 80768 KB Output is correct
75 Correct 49 ms 80720 KB Output is correct
76 Correct 103 ms 80820 KB Output is correct
77 Correct 210 ms 81748 KB Output is correct
78 Correct 48 ms 81672 KB Output is correct
79 Correct 132 ms 81532 KB Output is correct
80 Correct 45 ms 81744 KB Output is correct
81 Correct 63 ms 81632 KB Output is correct
82 Correct 209 ms 81744 KB Output is correct
83 Correct 42 ms 80100 KB Output is correct
84 Correct 43 ms 80080 KB Output is correct
85 Correct 63 ms 80464 KB Output is correct
86 Correct 43 ms 80340 KB Output is correct
87 Correct 44 ms 80392 KB Output is correct
88 Correct 40 ms 80808 KB Output is correct
89 Correct 51 ms 80884 KB Output is correct
90 Correct 86 ms 81068 KB Output is correct
91 Correct 193 ms 82048 KB Output is correct
92 Correct 66 ms 81916 KB Output is correct
93 Correct 115 ms 82048 KB Output is correct
94 Correct 42 ms 80204 KB Output is correct
95 Correct 51 ms 80268 KB Output is correct
96 Correct 39 ms 80184 KB Output is correct
97 Correct 38 ms 80300 KB Output is correct
98 Correct 37 ms 80208 KB Output is correct
99 Correct 44 ms 80044 KB Output is correct