Submission #1104098

# Submission time Handle Problem Language Result Execution time Memory
1104098 2024-10-22T17:43:53 Z dophu K blocks (IZhO14_blocks) C++17
53 / 100
1000 ms 83800 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const ll inf=1e17;
const ll N=1e5+2;
const ll blocks=1e2+2;
ll dp[N][blocks];
ll rm[N][32];
ll a[N];
ll n,k;
void build(ll lgg) {
    for (ll i=1;i<=lgg;i++) {
        for (ll j=1;j+(1<<i)-1<=n;j++) {
            rm[j][i]=max(rm[j][i-1],rm[j+(1<<(i-1))][i-1]);
        }
    }
}
ll get(ll l,ll r) {
    ll k=__lg(r-l+1);
    return max(rm[l][k],rm[r-(1<<k)+1][k]);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("blocks.in","r")) {
        freopen("blocks.in","r",stdin);
        freopen("blocks.out","w",stdout);
    }
    memset(dp,0x3f3f,sizeof(dp));
    cin>>n>>k;
    for (ll i=1;i<=n;i++) {
        cin>>a[i];
        rm[i][0]=a[i];
    }
    build(__lg(n));
    for (ll i=1;i<=n;i++) {
        dp[i][1]=get(1,i);
    }
    for (ll i=2;i<=n;i++) {
        for (ll j=2;j<=min(i,k);j++) {
            for (ll g=j-1;g<=i-1;g++) {
                dp[i][j]=min(dp[i][j],dp[g][j-1]+get(g+1,i));
            }
        }
    }
    cout<<dp[n][k];
    return 0;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen("blocks.in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen("blocks.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 83280 KB Output is correct
2 Correct 11 ms 83280 KB Output is correct
3 Correct 11 ms 83172 KB Output is correct
4 Correct 11 ms 83280 KB Output is correct
5 Correct 11 ms 83392 KB Output is correct
6 Correct 11 ms 83280 KB Output is correct
7 Correct 11 ms 83448 KB Output is correct
8 Correct 11 ms 83160 KB Output is correct
9 Correct 11 ms 83280 KB Output is correct
10 Correct 11 ms 83300 KB Output is correct
11 Correct 11 ms 83280 KB Output is correct
12 Correct 11 ms 83280 KB Output is correct
13 Correct 11 ms 83280 KB Output is correct
14 Correct 11 ms 83280 KB Output is correct
15 Correct 11 ms 83196 KB Output is correct
16 Correct 11 ms 83280 KB Output is correct
17 Correct 11 ms 83192 KB Output is correct
18 Correct 16 ms 81232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 81152 KB Output is correct
2 Correct 25 ms 83528 KB Output is correct
3 Correct 20 ms 81128 KB Output is correct
4 Correct 22 ms 81232 KB Output is correct
5 Correct 14 ms 81232 KB Output is correct
6 Correct 11 ms 83220 KB Output is correct
7 Correct 11 ms 83280 KB Output is correct
8 Correct 11 ms 83280 KB Output is correct
9 Correct 11 ms 83280 KB Output is correct
10 Correct 15 ms 81232 KB Output is correct
11 Correct 10 ms 81232 KB Output is correct
12 Correct 14 ms 81128 KB Output is correct
13 Correct 18 ms 81132 KB Output is correct
14 Correct 11 ms 81232 KB Output is correct
15 Correct 11 ms 83280 KB Output is correct
16 Correct 11 ms 81404 KB Output is correct
17 Correct 13 ms 81248 KB Output is correct
18 Correct 11 ms 83280 KB Output is correct
19 Correct 15 ms 81232 KB Output is correct
20 Correct 12 ms 83280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 83280 KB Output is correct
2 Correct 11 ms 83280 KB Output is correct
3 Correct 11 ms 83172 KB Output is correct
4 Correct 11 ms 83280 KB Output is correct
5 Correct 11 ms 83392 KB Output is correct
6 Correct 11 ms 83280 KB Output is correct
7 Correct 11 ms 83448 KB Output is correct
8 Correct 11 ms 83160 KB Output is correct
9 Correct 11 ms 83280 KB Output is correct
10 Correct 11 ms 83300 KB Output is correct
11 Correct 11 ms 83280 KB Output is correct
12 Correct 11 ms 83280 KB Output is correct
13 Correct 11 ms 83280 KB Output is correct
14 Correct 11 ms 83280 KB Output is correct
15 Correct 11 ms 83196 KB Output is correct
16 Correct 11 ms 83280 KB Output is correct
17 Correct 11 ms 83192 KB Output is correct
18 Correct 16 ms 81232 KB Output is correct
19 Correct 17 ms 81152 KB Output is correct
20 Correct 25 ms 83528 KB Output is correct
21 Correct 20 ms 81128 KB Output is correct
22 Correct 22 ms 81232 KB Output is correct
23 Correct 14 ms 81232 KB Output is correct
24 Correct 11 ms 83220 KB Output is correct
25 Correct 11 ms 83280 KB Output is correct
26 Correct 11 ms 83280 KB Output is correct
27 Correct 11 ms 83280 KB Output is correct
28 Correct 15 ms 81232 KB Output is correct
29 Correct 10 ms 81232 KB Output is correct
30 Correct 14 ms 81128 KB Output is correct
31 Correct 18 ms 81132 KB Output is correct
32 Correct 11 ms 81232 KB Output is correct
33 Correct 11 ms 83280 KB Output is correct
34 Correct 11 ms 81404 KB Output is correct
35 Correct 13 ms 81248 KB Output is correct
36 Correct 11 ms 83280 KB Output is correct
37 Correct 15 ms 81232 KB Output is correct
38 Correct 12 ms 83280 KB Output is correct
39 Correct 12 ms 83280 KB Output is correct
40 Correct 13 ms 81228 KB Output is correct
41 Correct 15 ms 81232 KB Output is correct
42 Correct 12 ms 83384 KB Output is correct
43 Correct 12 ms 83280 KB Output is correct
44 Correct 12 ms 83280 KB Output is correct
45 Correct 11 ms 83280 KB Output is correct
46 Correct 11 ms 83280 KB Output is correct
47 Correct 12 ms 83280 KB Output is correct
48 Correct 16 ms 81232 KB Output is correct
49 Correct 24 ms 81244 KB Output is correct
50 Correct 25 ms 81224 KB Output is correct
51 Correct 25 ms 81224 KB Output is correct
52 Correct 22 ms 81232 KB Output is correct
53 Correct 17 ms 81232 KB Output is correct
54 Correct 12 ms 83280 KB Output is correct
55 Correct 21 ms 81232 KB Output is correct
56 Correct 27 ms 81232 KB Output is correct
57 Correct 27 ms 81224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 83280 KB Output is correct
2 Correct 11 ms 83280 KB Output is correct
3 Correct 11 ms 83172 KB Output is correct
4 Correct 11 ms 83280 KB Output is correct
5 Correct 11 ms 83392 KB Output is correct
6 Correct 11 ms 83280 KB Output is correct
7 Correct 11 ms 83448 KB Output is correct
8 Correct 11 ms 83160 KB Output is correct
9 Correct 11 ms 83280 KB Output is correct
10 Correct 11 ms 83300 KB Output is correct
11 Correct 11 ms 83280 KB Output is correct
12 Correct 11 ms 83280 KB Output is correct
13 Correct 11 ms 83280 KB Output is correct
14 Correct 11 ms 83280 KB Output is correct
15 Correct 11 ms 83196 KB Output is correct
16 Correct 11 ms 83280 KB Output is correct
17 Correct 11 ms 83192 KB Output is correct
18 Correct 16 ms 81232 KB Output is correct
19 Correct 17 ms 81152 KB Output is correct
20 Correct 25 ms 83528 KB Output is correct
21 Correct 20 ms 81128 KB Output is correct
22 Correct 22 ms 81232 KB Output is correct
23 Correct 14 ms 81232 KB Output is correct
24 Correct 11 ms 83220 KB Output is correct
25 Correct 11 ms 83280 KB Output is correct
26 Correct 11 ms 83280 KB Output is correct
27 Correct 11 ms 83280 KB Output is correct
28 Correct 15 ms 81232 KB Output is correct
29 Correct 10 ms 81232 KB Output is correct
30 Correct 14 ms 81128 KB Output is correct
31 Correct 18 ms 81132 KB Output is correct
32 Correct 11 ms 81232 KB Output is correct
33 Correct 11 ms 83280 KB Output is correct
34 Correct 11 ms 81404 KB Output is correct
35 Correct 13 ms 81248 KB Output is correct
36 Correct 11 ms 83280 KB Output is correct
37 Correct 15 ms 81232 KB Output is correct
38 Correct 12 ms 83280 KB Output is correct
39 Correct 12 ms 83280 KB Output is correct
40 Correct 13 ms 81228 KB Output is correct
41 Correct 15 ms 81232 KB Output is correct
42 Correct 12 ms 83384 KB Output is correct
43 Correct 12 ms 83280 KB Output is correct
44 Correct 12 ms 83280 KB Output is correct
45 Correct 11 ms 83280 KB Output is correct
46 Correct 11 ms 83280 KB Output is correct
47 Correct 12 ms 83280 KB Output is correct
48 Correct 16 ms 81232 KB Output is correct
49 Correct 24 ms 81244 KB Output is correct
50 Correct 25 ms 81224 KB Output is correct
51 Correct 25 ms 81224 KB Output is correct
52 Correct 22 ms 81232 KB Output is correct
53 Correct 17 ms 81232 KB Output is correct
54 Correct 12 ms 83280 KB Output is correct
55 Correct 21 ms 81232 KB Output is correct
56 Correct 27 ms 81232 KB Output is correct
57 Correct 27 ms 81224 KB Output is correct
58 Execution timed out 1069 ms 83800 KB Time limit exceeded
59 Halted 0 ms 0 KB -