Submission #744199

# Submission time Handle Problem Language Result Execution time Memory
744199 2023-05-18T09:08:49 Z viwlesxq Bali Sculptures (APIO15_sculpture) C++17
100 / 100
779 ms 20300 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef string str;

const ll inf = 1e18;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    ll y[n + 1];
    for (int i = 0; i < n; ++i) {
        cin >> y[i];
    }
    if (n <= 20) {
        ll ans = inf;
        for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
            int cnt = __builtin_popcount(mask) + 1;
            if (cnt < a || cnt > b) {
                continue;
            }
            ll cur = 0;
            ll sum = y[0];
            for (int bit = 0; bit < n - 1; ++bit) {
                if (mask & (1 << bit)) {
                    cur |= sum;
                    sum = y[bit + 1];
                } else {
                    sum += y[bit + 1];
                }
            }
            cur |= sum;
            ans = min(ans, cur);
        }
        cout << ans;
    } else if (*max_element(y, y + n) <= 20) {
        ll pref[n + 1];
        bool dp[n + 1][n + 1][2001];
        memset(dp, false, sizeof(dp));
        pref[0] = 0;
        for (int i = 1; i <= n; ++i) {
            pref[i] = pref[i - 1] + y[i - 1];
        }
        for (int i = 1; i <= n; ++i) {
            dp[i][1][pref[i]] = true; 
        }
        for (int k = 2; k <= b; ++k) {
            for (int i = 1; i <= n; ++i) {
                for (int j = i - 1; j >= 1; --j) {
                    for (int x = 0; x < 2001; ++x) {
                        if (dp[j][k - 1][x]) {
                            dp[i][k][x | (pref[i] - pref[j])] = true;
                        }
                    }
                }
            }
        }
        ll ans = inf;
        for (int k = a; k <= b; ++k) {
            for (int x = 0; x < 2001; ++x) {
                if (dp[n][k][x]) {
                    ans = min(ans, (ll)x);
                }
            }
        }
        cout << ans;
    } else if (n <= 100) {
        ll mask = 0;
        for (int bit = 60; bit >= 0; --bit) {
            bool can = false;
            mask |= 1ll << bit;
            vector <vector <bool>> dp(n + 1, vector <bool> (n + 1, false));
            dp[0][0] = true;
            for (int k = 0; k <= b; ++k) {
                for (int i = 0; i < n; ++i) {
                    ll sum = 0;
                    if (dp[k][i]) {
                        for (int j = i; j < n; ++j) {
                            sum += y[j];
                            if ((sum & mask) == 0) {
                                dp[k + 1][j + 1] = true;
                            }
                        }
                    }
                }
            }
            for (int k = a; k <= b; ++k) {
                if (dp[k][n]) {
                    can = true;
                }
            }
            if (!can) {
                mask ^= 1ll << bit;
            }
        }
        cout << (1ll << 61) - 1 - mask;
    } else {
        ll mask = 0;
        for (int bit = 60; bit >= 0; --bit) {
            mask |= 1ll << bit;
            vector <int> dp(n + 1, 100000);
            dp[0] = 0;
            for (int i = 0; i < n; ++i) {
                ll sum = 0;
                if (dp[i] < 100000) {
                    for (int j = i; j < n; ++j) {
                        sum += y[j];
                        if ((sum & mask) == 0) {
                            dp[j + 1] = min(dp[j + 1], dp[i] + 1);
                        }
                    }
                }
            }
            if (dp[n] > b) {
                mask ^= 1ll << bit;
            }
        }
        cout << (1ll << 61) - 1 - mask;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 232 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 29 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 4 ms 212 KB Output is correct
22 Correct 4 ms 312 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 5 ms 212 KB Output is correct
26 Correct 27 ms 304 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 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 5 ms 316 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 28 ms 212 KB Output is correct
34 Correct 30 ms 212 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 29 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 3 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 28 ms 316 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 5 ms 212 KB Output is correct
22 Correct 5 ms 212 KB Output is correct
23 Correct 4 ms 312 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 26 ms 316 KB Output is correct
27 Correct 6 ms 1260 KB Output is correct
28 Correct 6 ms 1636 KB Output is correct
29 Correct 6 ms 3284 KB Output is correct
30 Correct 24 ms 3948 KB Output is correct
31 Correct 37 ms 5332 KB Output is correct
32 Correct 38 ms 5332 KB Output is correct
33 Correct 4 ms 5332 KB Output is correct
34 Correct 44 ms 5388 KB Output is correct
35 Correct 33 ms 5404 KB Output is correct
36 Correct 20 ms 5404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 29 ms 316 KB Output is correct
14 Correct 7 ms 1260 KB Output is correct
15 Correct 7 ms 1564 KB Output is correct
16 Correct 6 ms 3296 KB Output is correct
17 Correct 25 ms 3932 KB Output is correct
18 Correct 37 ms 5332 KB Output is correct
19 Correct 40 ms 5392 KB Output is correct
20 Correct 3 ms 5332 KB Output is correct
21 Correct 38 ms 5388 KB Output is correct
22 Correct 32 ms 5332 KB Output is correct
23 Correct 19 ms 5332 KB Output is correct
24 Correct 47 ms 5592 KB Output is correct
25 Correct 38 ms 8788 KB Output is correct
26 Correct 112 ms 12524 KB Output is correct
27 Correct 343 ms 16864 KB Output is correct
28 Correct 765 ms 20264 KB Output is correct
29 Correct 718 ms 20268 KB Output is correct
30 Correct 11 ms 20180 KB Output is correct
31 Correct 421 ms 20268 KB Output is correct
32 Correct 559 ms 20180 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 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 28 ms 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 4 ms 212 KB Output is correct
22 Correct 4 ms 212 KB Output is correct
23 Correct 4 ms 312 KB Output is correct
24 Correct 3 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 26 ms 296 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 4 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 25 ms 212 KB Output is correct
34 Correct 29 ms 212 KB Output is correct
35 Correct 2 ms 228 KB Output is correct
36 Correct 32 ms 212 KB Output is correct
37 Correct 7 ms 1236 KB Output is correct
38 Correct 5 ms 1620 KB Output is correct
39 Correct 6 ms 3284 KB Output is correct
40 Correct 23 ms 3924 KB Output is correct
41 Correct 38 ms 5332 KB Output is correct
42 Correct 39 ms 5332 KB Output is correct
43 Correct 4 ms 5360 KB Output is correct
44 Correct 42 ms 5332 KB Output is correct
45 Correct 31 ms 5400 KB Output is correct
46 Correct 27 ms 5332 KB Output is correct
47 Correct 53 ms 5588 KB Output is correct
48 Correct 37 ms 8788 KB Output is correct
49 Correct 110 ms 12524 KB Output is correct
50 Correct 380 ms 16864 KB Output is correct
51 Correct 744 ms 20264 KB Output is correct
52 Correct 740 ms 20276 KB Output is correct
53 Correct 11 ms 20180 KB Output is correct
54 Correct 380 ms 20264 KB Output is correct
55 Correct 593 ms 20264 KB Output is correct
56 Correct 3 ms 212 KB Output is correct
57 Correct 6 ms 212 KB Output is correct
58 Correct 12 ms 212 KB Output is correct
59 Correct 16 ms 212 KB Output is correct
60 Correct 15 ms 212 KB Output is correct
61 Correct 2 ms 212 KB Output is correct
62 Correct 16 ms 212 KB Output is correct
63 Correct 17 ms 320 KB Output is correct
64 Correct 511 ms 16504 KB Output is correct
65 Correct 3 ms 212 KB Output is correct
66 Correct 3 ms 320 KB Output is correct
67 Correct 5 ms 212 KB Output is correct
68 Correct 11 ms 328 KB Output is correct
69 Correct 16 ms 328 KB Output is correct
70 Correct 14 ms 212 KB Output is correct
71 Correct 2 ms 212 KB Output is correct
72 Correct 17 ms 324 KB Output is correct
73 Correct 17 ms 212 KB Output is correct
74 Correct 17 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 276 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 30 ms 212 KB Output is correct
14 Correct 0 ms 212 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 4 ms 212 KB Output is correct
19 Correct 3 ms 212 KB Output is correct
20 Correct 29 ms 212 KB Output is correct
21 Correct 31 ms 212 KB Output is correct
22 Correct 3 ms 212 KB Output is correct
23 Correct 32 ms 280 KB Output is correct
24 Correct 11 ms 1236 KB Output is correct
25 Correct 6 ms 1636 KB Output is correct
26 Correct 7 ms 3292 KB Output is correct
27 Correct 23 ms 4052 KB Output is correct
28 Correct 41 ms 5332 KB Output is correct
29 Correct 52 ms 5380 KB Output is correct
30 Correct 3 ms 5332 KB Output is correct
31 Correct 49 ms 5384 KB Output is correct
32 Correct 33 ms 5332 KB Output is correct
33 Correct 24 ms 5404 KB Output is correct
34 Correct 39 ms 5592 KB Output is correct
35 Correct 34 ms 8820 KB Output is correct
36 Correct 110 ms 12488 KB Output is correct
37 Correct 338 ms 16860 KB Output is correct
38 Correct 779 ms 20264 KB Output is correct
39 Correct 741 ms 20300 KB Output is correct
40 Correct 13 ms 20180 KB Output is correct
41 Correct 416 ms 20264 KB Output is correct
42 Correct 589 ms 20264 KB Output is correct
43 Correct 3 ms 212 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 12 ms 212 KB Output is correct
46 Correct 16 ms 332 KB Output is correct
47 Correct 18 ms 304 KB Output is correct
48 Correct 2 ms 212 KB Output is correct
49 Correct 17 ms 324 KB Output is correct
50 Correct 18 ms 328 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 8 ms 324 KB Output is correct
53 Correct 9 ms 212 KB Output is correct
54 Correct 28 ms 328 KB Output is correct
55 Correct 22 ms 212 KB Output is correct
56 Correct 63 ms 340 KB Output is correct
57 Correct 64 ms 340 KB Output is correct
58 Correct 83 ms 340 KB Output is correct
59 Correct 84 ms 352 KB Output is correct
60 Correct 66 ms 344 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 9 ms 212 KB Output is correct
63 Correct 31 ms 340 KB Output is correct
64 Correct 15 ms 328 KB Output is correct
65 Correct 31 ms 340 KB Output is correct
66 Correct 47 ms 340 KB Output is correct
67 Correct 61 ms 340 KB Output is correct
68 Correct 130 ms 340 KB Output is correct
69 Correct 59 ms 340 KB Output is correct