Submission #742319

# Submission time Handle Problem Language Result Execution time Memory
742319 2023-05-16T05:56:51 Z viwlesxq Bali Sculptures (APIO15_sculpture) C++17
25 / 100
35 ms 800 KB
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef string str;

const int N = 101;
const int R = 21;
const int Y = 501;
const ll inf = 1e18;

ll y[N], pref[N];
bool dp[N][R][Y];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    if (n <= 20) {
        ll ans = inf;
        for (int i = 0; i < n; ++i) {
            cin >> y[i];
        }
        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 {
        for (int i = 1; i <= n; ++i) {
            cin >> y[i];
            pref[i] = pref[i - 1] + y[i];
        }
        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 < Y; ++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 < Y; ++x) {
                if (dp[n][k][x]) {
                    ans = min(ans, (ll)x);
                }
            }
        }
        cout << ans;
    }
}
# 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 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 29 ms 332 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 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 1 ms 212 KB Output is correct
20 Correct 0 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 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 27 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 4 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 28 ms 320 KB Output is correct
34 Correct 31 ms 332 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 30 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 0 ms 212 KB Output is correct
4 Correct 1 ms 292 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 328 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 31 ms 324 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 0 ms 212 KB Output is correct
20 Correct 0 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 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 30 ms 212 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 496 KB Output is correct
30 Correct 11 ms 716 KB Output is correct
31 Correct 12 ms 800 KB Output is correct
32 Correct 10 ms 796 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 10 ms 796 KB Output is correct
35 Correct 10 ms 724 KB Output is correct
36 Correct 6 ms 596 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 0 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 35 ms 304 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 16 ms 788 KB Output is correct
19 Correct 10 ms 724 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 10 ms 768 KB Output is correct
22 Correct 9 ms 724 KB Output is correct
23 Correct 7 ms 596 KB Output is correct
24 Correct 13 ms 708 KB Output is correct
25 Incorrect 12 ms 724 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 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 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 32 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 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 1 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 5 ms 324 KB Output is correct
22 Correct 5 ms 324 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 2 ms 212 KB Output is correct
25 Correct 4 ms 212 KB Output is correct
26 Correct 29 ms 212 KB Output is correct
27 Correct 0 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 4 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
33 Correct 30 ms 320 KB Output is correct
34 Correct 32 ms 212 KB Output is correct
35 Correct 2 ms 212 KB Output is correct
36 Correct 31 ms 212 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 7 ms 596 KB Output is correct
41 Correct 11 ms 712 KB Output is correct
42 Correct 11 ms 688 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 11 ms 724 KB Output is correct
45 Correct 9 ms 692 KB Output is correct
46 Correct 6 ms 708 KB Output is correct
47 Correct 12 ms 724 KB Output is correct
48 Incorrect 12 ms 708 KB Output isn't correct
49 Halted 0 ms 0 KB -
# 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 1 ms 232 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 212 KB Output is correct
14 Correct 1 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 1 ms 212 KB Output is correct
18 Correct 5 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 30 ms 212 KB Output is correct
21 Correct 31 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 30 ms 212 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 7 ms 712 KB Output is correct
28 Correct 11 ms 712 KB Output is correct
29 Correct 10 ms 716 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 11 ms 744 KB Output is correct
32 Correct 9 ms 724 KB Output is correct
33 Correct 6 ms 724 KB Output is correct
34 Correct 13 ms 724 KB Output is correct
35 Incorrect 11 ms 792 KB Output isn't correct
36 Halted 0 ms 0 KB -