Submission #885074

# Submission time Handle Problem Language Result Execution time Memory
885074 2023-12-09T01:08:20 Z vjudge1 K blocks (IZhO14_blocks) C++17
100 / 100
173 ms 84876 KB
#include <bits/stdc++.h>
using namespace std;
long long dp[105][100005], a[100005];
int main()
{
    long long n, k;
    cin >> n >> k;
    long long mx = 0;
    memset(dp, 1000000007, sizeof(dp));
    for (long long i = 1; i <= n; i++) 
    {
        cin >> a[i];
        mx = max(mx, a[i]);
        dp[1][i] = mx;
    }
    for (long long i = 2; i <= k; i++) 
    {
        stack<long long> s1, s2;
        for (long long j = 1; j <= n; j++) 
        {
            long long tmp = dp[i-1][j-1];
            while (s1.size() && s1.top() < a[j]) 
            {
                tmp = min(tmp, s2.top());
                s1.pop();
                s2.pop();
            }
            if (s1.empty() || tmp+a[j] < s1.top()+s2.top())
            {
                s1.push(a[j]);
                s2.push(tmp);
            }
            if (j >= i) dp[i][j] = s1.top()+s2.top();
        }
    }
    cout << dp[k][n] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 83504 KB Output is correct
2 Correct 12 ms 83036 KB Output is correct
3 Correct 10 ms 83036 KB Output is correct
4 Correct 11 ms 83036 KB Output is correct
5 Correct 10 ms 83036 KB Output is correct
6 Correct 11 ms 83132 KB Output is correct
7 Correct 12 ms 83036 KB Output is correct
8 Correct 10 ms 83228 KB Output is correct
9 Correct 11 ms 83008 KB Output is correct
10 Correct 11 ms 83036 KB Output is correct
11 Correct 10 ms 83032 KB Output is correct
12 Correct 11 ms 83032 KB Output is correct
13 Correct 10 ms 83128 KB Output is correct
14 Correct 10 ms 83036 KB Output is correct
15 Correct 10 ms 83216 KB Output is correct
16 Correct 10 ms 83036 KB Output is correct
17 Correct 10 ms 83000 KB Output is correct
18 Correct 11 ms 83036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 83036 KB Output is correct
2 Correct 11 ms 83132 KB Output is correct
3 Correct 11 ms 83032 KB Output is correct
4 Correct 11 ms 83032 KB Output is correct
5 Correct 10 ms 83032 KB Output is correct
6 Correct 10 ms 83032 KB Output is correct
7 Correct 10 ms 83032 KB Output is correct
8 Correct 10 ms 83032 KB Output is correct
9 Correct 12 ms 83032 KB Output is correct
10 Correct 10 ms 83036 KB Output is correct
11 Correct 10 ms 83036 KB Output is correct
12 Correct 10 ms 83036 KB Output is correct
13 Correct 11 ms 83036 KB Output is correct
14 Correct 10 ms 83196 KB Output is correct
15 Correct 10 ms 83036 KB Output is correct
16 Correct 10 ms 83036 KB Output is correct
17 Correct 10 ms 83036 KB Output is correct
18 Correct 10 ms 83000 KB Output is correct
19 Correct 10 ms 83036 KB Output is correct
20 Correct 11 ms 83192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 83504 KB Output is correct
2 Correct 12 ms 83036 KB Output is correct
3 Correct 10 ms 83036 KB Output is correct
4 Correct 11 ms 83036 KB Output is correct
5 Correct 10 ms 83036 KB Output is correct
6 Correct 11 ms 83132 KB Output is correct
7 Correct 12 ms 83036 KB Output is correct
8 Correct 10 ms 83228 KB Output is correct
9 Correct 11 ms 83008 KB Output is correct
10 Correct 11 ms 83036 KB Output is correct
11 Correct 10 ms 83032 KB Output is correct
12 Correct 11 ms 83032 KB Output is correct
13 Correct 10 ms 83128 KB Output is correct
14 Correct 10 ms 83036 KB Output is correct
15 Correct 10 ms 83216 KB Output is correct
16 Correct 10 ms 83036 KB Output is correct
17 Correct 10 ms 83000 KB Output is correct
18 Correct 11 ms 83036 KB Output is correct
19 Correct 10 ms 83036 KB Output is correct
20 Correct 11 ms 83132 KB Output is correct
21 Correct 11 ms 83032 KB Output is correct
22 Correct 11 ms 83032 KB Output is correct
23 Correct 10 ms 83032 KB Output is correct
24 Correct 10 ms 83032 KB Output is correct
25 Correct 10 ms 83032 KB Output is correct
26 Correct 10 ms 83032 KB Output is correct
27 Correct 12 ms 83032 KB Output is correct
28 Correct 10 ms 83036 KB Output is correct
29 Correct 10 ms 83036 KB Output is correct
30 Correct 10 ms 83036 KB Output is correct
31 Correct 11 ms 83036 KB Output is correct
32 Correct 10 ms 83196 KB Output is correct
33 Correct 10 ms 83036 KB Output is correct
34 Correct 10 ms 83036 KB Output is correct
35 Correct 10 ms 83036 KB Output is correct
36 Correct 10 ms 83000 KB Output is correct
37 Correct 10 ms 83036 KB Output is correct
38 Correct 11 ms 83192 KB Output is correct
39 Correct 11 ms 83036 KB Output is correct
40 Correct 11 ms 83408 KB Output is correct
41 Correct 12 ms 83032 KB Output is correct
42 Correct 11 ms 83032 KB Output is correct
43 Correct 10 ms 83036 KB Output is correct
44 Correct 10 ms 83000 KB Output is correct
45 Correct 11 ms 82996 KB Output is correct
46 Correct 10 ms 83032 KB Output is correct
47 Correct 10 ms 83036 KB Output is correct
48 Correct 11 ms 83032 KB Output is correct
49 Correct 10 ms 83036 KB Output is correct
50 Correct 10 ms 83036 KB Output is correct
51 Correct 10 ms 83036 KB Output is correct
52 Correct 11 ms 83036 KB Output is correct
53 Correct 10 ms 83036 KB Output is correct
54 Correct 10 ms 83036 KB Output is correct
55 Correct 11 ms 83036 KB Output is correct
56 Correct 10 ms 83004 KB Output is correct
57 Correct 11 ms 83036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 83504 KB Output is correct
2 Correct 12 ms 83036 KB Output is correct
3 Correct 10 ms 83036 KB Output is correct
4 Correct 11 ms 83036 KB Output is correct
5 Correct 10 ms 83036 KB Output is correct
6 Correct 11 ms 83132 KB Output is correct
7 Correct 12 ms 83036 KB Output is correct
8 Correct 10 ms 83228 KB Output is correct
9 Correct 11 ms 83008 KB Output is correct
10 Correct 11 ms 83036 KB Output is correct
11 Correct 10 ms 83032 KB Output is correct
12 Correct 11 ms 83032 KB Output is correct
13 Correct 10 ms 83128 KB Output is correct
14 Correct 10 ms 83036 KB Output is correct
15 Correct 10 ms 83216 KB Output is correct
16 Correct 10 ms 83036 KB Output is correct
17 Correct 10 ms 83000 KB Output is correct
18 Correct 11 ms 83036 KB Output is correct
19 Correct 10 ms 83036 KB Output is correct
20 Correct 11 ms 83132 KB Output is correct
21 Correct 11 ms 83032 KB Output is correct
22 Correct 11 ms 83032 KB Output is correct
23 Correct 10 ms 83032 KB Output is correct
24 Correct 10 ms 83032 KB Output is correct
25 Correct 10 ms 83032 KB Output is correct
26 Correct 10 ms 83032 KB Output is correct
27 Correct 12 ms 83032 KB Output is correct
28 Correct 10 ms 83036 KB Output is correct
29 Correct 10 ms 83036 KB Output is correct
30 Correct 10 ms 83036 KB Output is correct
31 Correct 11 ms 83036 KB Output is correct
32 Correct 10 ms 83196 KB Output is correct
33 Correct 10 ms 83036 KB Output is correct
34 Correct 10 ms 83036 KB Output is correct
35 Correct 10 ms 83036 KB Output is correct
36 Correct 10 ms 83000 KB Output is correct
37 Correct 10 ms 83036 KB Output is correct
38 Correct 11 ms 83192 KB Output is correct
39 Correct 11 ms 83036 KB Output is correct
40 Correct 11 ms 83408 KB Output is correct
41 Correct 12 ms 83032 KB Output is correct
42 Correct 11 ms 83032 KB Output is correct
43 Correct 10 ms 83036 KB Output is correct
44 Correct 10 ms 83000 KB Output is correct
45 Correct 11 ms 82996 KB Output is correct
46 Correct 10 ms 83032 KB Output is correct
47 Correct 10 ms 83036 KB Output is correct
48 Correct 11 ms 83032 KB Output is correct
49 Correct 10 ms 83036 KB Output is correct
50 Correct 10 ms 83036 KB Output is correct
51 Correct 10 ms 83036 KB Output is correct
52 Correct 11 ms 83036 KB Output is correct
53 Correct 10 ms 83036 KB Output is correct
54 Correct 10 ms 83036 KB Output is correct
55 Correct 11 ms 83036 KB Output is correct
56 Correct 10 ms 83004 KB Output is correct
57 Correct 11 ms 83036 KB Output is correct
58 Correct 16 ms 83292 KB Output is correct
59 Correct 20 ms 83548 KB Output is correct
60 Correct 22 ms 83544 KB Output is correct
61 Correct 46 ms 83548 KB Output is correct
62 Correct 106 ms 83908 KB Output is correct
63 Correct 34 ms 84060 KB Output is correct
64 Correct 65 ms 84072 KB Output is correct
65 Correct 11 ms 83036 KB Output is correct
66 Correct 10 ms 83036 KB Output is correct
67 Correct 11 ms 83036 KB Output is correct
68 Correct 11 ms 83036 KB Output is correct
69 Correct 11 ms 83156 KB Output is correct
70 Correct 11 ms 83036 KB Output is correct
71 Correct 22 ms 83356 KB Output is correct
72 Correct 14 ms 83292 KB Output is correct
73 Correct 14 ms 83196 KB Output is correct
74 Correct 20 ms 83692 KB Output is correct
75 Correct 22 ms 83548 KB Output is correct
76 Correct 47 ms 83688 KB Output is correct
77 Correct 109 ms 84064 KB Output is correct
78 Correct 34 ms 84060 KB Output is correct
79 Correct 65 ms 84032 KB Output is correct
80 Correct 31 ms 84056 KB Output is correct
81 Correct 38 ms 84060 KB Output is correct
82 Correct 110 ms 84060 KB Output is correct
83 Correct 10 ms 83032 KB Output is correct
84 Correct 11 ms 83036 KB Output is correct
85 Correct 24 ms 83292 KB Output is correct
86 Correct 13 ms 83292 KB Output is correct
87 Correct 16 ms 83292 KB Output is correct
88 Correct 20 ms 83544 KB Output is correct
89 Correct 23 ms 83992 KB Output is correct
90 Correct 64 ms 84036 KB Output is correct
91 Correct 173 ms 84876 KB Output is correct
92 Correct 34 ms 84560 KB Output is correct
93 Correct 90 ms 84872 KB Output is correct
94 Correct 13 ms 83288 KB Output is correct
95 Correct 21 ms 83276 KB Output is correct
96 Correct 10 ms 83032 KB Output is correct
97 Correct 11 ms 83036 KB Output is correct
98 Correct 12 ms 83036 KB Output is correct
99 Correct 11 ms 83036 KB Output is correct