Submission #1008501

# Submission time Handle Problem Language Result Execution time Memory
1008501 2024-06-26T13:45:19 Z VMaksimoski008 K blocks (IZhO14_blocks) C++17
53 / 100
237 ms 41304 KB
#include <iostream>
using namespace std; 
using ll = long long;
 
const int LOG = 20;
const int maxn = 1e5 + 5;

int log_dp[maxn+5];
int T[maxn+5][LOG];
ll dp[maxn+5][105];

int query(int l, int r) {
    int k = log_dp[r-l+1];
    return max(T[l][k], T[r-(1<<k)+1][k]);
}

void f(int l, int r, int tl, int tr, int j) {
    if(l > r) return ;
    int tm = (l + r) / 2, p = tl;

    for(int i=tl; i<=min(tm, tr); i++) {
        ll v = dp[i-1][j-1] + query(i, tm);
        if(v < dp[tm][j]) {
            dp[tm][j] = v;
            p = i;
        }
    }

    f(l, tm-1, tl, p, j);
    f(tm+1, r, p, tr, j);
}
 
signed main() {
    log_dp[1] = 0;
    for(int i=2; i<=maxn; i++) log_dp[i] = log_dp[i/2] + 1;

    int n, k;
    cin >> n >> k;
 
    int v[n+1];
    for(int i=1; i<=n; i++) cin >> v[i], T[i][0] = v[i];

    for(int j=1; j<LOG; j++)
        for(int i=1; i+(1<<j)-1<=n; i++)
            T[i][j] = max(T[i][j-1], T[i+(1<<(j-1))][j-1]);
    for(int i=0; i<=n; i++)
        for(int j=0; j<=k; j++) dp[i][j] = 1e18;
 
    dp[0][0] = 0;

    if(n <= 100) {
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=k; j++) {
                int mx = 0;
                for(int x=i; x>=1; x--) {
                    mx = max(mx, v[x]);
                    dp[i][j] = min(dp[i][j], dp[x-1][j-1] + mx);
                }
            }
        }
        cout << dp[n][k] << '\n';
        return 0;
    }

    for(int j=1; j<=k; j++) f(1, n, 1, n, j);
    cout << dp[n][k] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 608 KB Output is correct
4 Correct 1 ms 628 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 840 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 0 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 608 KB Output is correct
4 Correct 1 ms 628 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 840 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 860 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 860 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 0 ms 860 KB Output is correct
37 Correct 0 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 0 ms 656 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 860 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 836 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 608 KB Output is correct
4 Correct 1 ms 628 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 0 ms 840 KB Output is correct
14 Correct 0 ms 860 KB Output is correct
15 Correct 0 ms 860 KB Output is correct
16 Correct 0 ms 860 KB Output is correct
17 Correct 1 ms 856 KB Output is correct
18 Correct 0 ms 860 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 860 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 860 KB Output is correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 0 ms 860 KB Output is correct
37 Correct 0 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 0 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 0 ms 656 KB Output is correct
43 Correct 0 ms 604 KB Output is correct
44 Correct 0 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 604 KB Output is correct
50 Correct 0 ms 604 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 860 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 836 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 18 ms 10072 KB Output is correct
59 Correct 25 ms 41220 KB Output is correct
60 Correct 43 ms 41296 KB Output is correct
61 Incorrect 237 ms 41304 KB Output isn't correct
62 Halted 0 ms 0 KB -