Submission #581182

# Submission time Handle Problem Language Result Execution time Memory
581182 2022-06-22T10:32:16 Z FatihSolak K blocks (IZhO14_blocks) C++17
53 / 100
1000 ms 4044 KB
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int a[N];
int dp[N];
int ndp[N];
void solve(){
    int n,k;
    cin >> n >> k;
    for(int i = 1;i<=n;i++){
        cin >> a[i];
        dp[i] = 1e9;
    }
    for(int x = 1;x<=k;x++){
        for(int i = 0;i<=n;i++){
            ndp[i] = 1e9;
        }
        stack<pair<int,int>> st;
        multiset<int> s;
        for(int i = 1;i<=n;i++){
            int mini = dp[i-1];
            while(st.size() && a[i] >= a[st.top().first]){
                mini = min(mini,st.top().second);
                s.erase(s.find(a[st.top().first] + st.top().second));
                st.pop();
            }
            st.push({i,mini});
            s.insert(a[i]  + mini);
            ndp[i] = *s.begin();
        }
        for(int i = 0;i<=n;i++){
            dp[i] = ndp[i];
            //cout << dp[i] << " ";
        }
        //cout << endl;
    }
    cout << dp[n];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    #ifdef Local
        cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 328 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 324 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 244 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 328 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 324 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 244 KB Output is correct
56 Correct 2 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 12 ms 520 KB Output is correct
59 Correct 9 ms 1108 KB Output is correct
60 Correct 18 ms 1160 KB Output is correct
61 Correct 146 ms 1228 KB Output is correct
62 Correct 510 ms 2164 KB Output is correct
63 Correct 26 ms 2168 KB Output is correct
64 Correct 209 ms 2168 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 84 ms 496 KB Output is correct
72 Correct 3 ms 468 KB Output is correct
73 Correct 21 ms 516 KB Output is correct
74 Correct 8 ms 1108 KB Output is correct
75 Correct 27 ms 1108 KB Output is correct
76 Correct 283 ms 1140 KB Output is correct
77 Correct 831 ms 2160 KB Output is correct
78 Correct 28 ms 2132 KB Output is correct
79 Correct 369 ms 2156 KB Output is correct
80 Correct 22 ms 2132 KB Output is correct
81 Correct 82 ms 2172 KB Output is correct
82 Correct 846 ms 2168 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 2 ms 340 KB Output is correct
85 Correct 116 ms 696 KB Output is correct
86 Correct 4 ms 652 KB Output is correct
87 Correct 32 ms 716 KB Output is correct
88 Correct 11 ms 1996 KB Output is correct
89 Correct 47 ms 2004 KB Output is correct
90 Correct 464 ms 2012 KB Output is correct
91 Execution timed out 1081 ms 4044 KB Time limit exceeded
92 Halted 0 ms 0 KB -