Submission #162237

# Submission time Handle Problem Language Result Execution time Memory
162237 2019-11-07T09:18:19 Z rama_pang Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

int N, L, R;
vector<lint> A;
vector<lint> prefix_sum;
vector<vector<int8_t>> DP;

inline lint get(int l, int r) {
    return prefix_sum[r] - ((l > 0)? prefix_sum[l - 1] : 0);
}

int8_t dp(int n, int groups, lint mask) {
    if (n == N) 
        return (L <= groups && groups <= R);
    if (n > N)
        return false;
    if (groups > R)
        return false;
    if (DP[n][groups] != -1)
        return DP[n][groups];
    
    int8_t &res = DP[n][groups];
    res = 0;

    for (int i = n; i < N; i++) 
        if ((get(n, i) | mask) == mask) 
            res |= dp(i + 1, groups + 1, mask);
    
    return res;
}

int8_t solve(lint mask) { // Check if it is possible to get beauty of a subset of mask
    DP.assign(N, vector<int8_t>(R, -1));
    return dp(0, 0, mask);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> L >> R;

    A.reserve(N), A.resize(N);
    prefix_sum.reserve(N), prefix_sum.resize(N);

    for (int i = 0; i < N; i++) {
        cin >> A[i];
        prefix_sum[i] = ((i > 0)? prefix_sum[i - 1] : 0) + A[i];
    }
    
    lint ans = (1ll << 62ll) - 1;
    for (lint bit = 61; bit >= 0; bit--) 
        if (solve(ans - (1ll << bit)) == 1) 
            ans -= (1ll << bit);
    
    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 13 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 380 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 8 ms 376 KB Output is correct
32 Correct 8 ms 376 KB Output is correct
33 Correct 2 ms 420 KB Output is correct
34 Correct 9 ms 376 KB Output is correct
35 Correct 8 ms 376 KB Output is correct
36 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 476 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 7 ms 376 KB Output is correct
18 Correct 9 ms 380 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
20 Correct 2 ms 424 KB Output is correct
21 Correct 8 ms 376 KB Output is correct
22 Correct 8 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 9 ms 376 KB Output is correct
25 Correct 8 ms 376 KB Output is correct
26 Correct 21 ms 376 KB Output is correct
27 Correct 47 ms 428 KB Output is correct
28 Correct 66 ms 436 KB Output is correct
29 Correct 64 ms 376 KB Output is correct
30 Correct 2 ms 404 KB Output is correct
31 Correct 54 ms 376 KB Output is correct
32 Correct 63 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 412 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 416 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 6 ms 376 KB Output is correct
41 Correct 8 ms 376 KB Output is correct
42 Correct 8 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 8 ms 380 KB Output is correct
45 Correct 8 ms 376 KB Output is correct
46 Correct 6 ms 380 KB Output is correct
47 Correct 8 ms 376 KB Output is correct
48 Correct 8 ms 380 KB Output is correct
49 Correct 22 ms 376 KB Output is correct
50 Correct 46 ms 380 KB Output is correct
51 Correct 64 ms 376 KB Output is correct
52 Correct 66 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 54 ms 504 KB Output is correct
55 Correct 63 ms 376 KB Output is correct
56 Correct 20 ms 376 KB Output is correct
57 Correct 12 ms 376 KB Output is correct
58 Correct 25 ms 376 KB Output is correct
59 Correct 36 ms 400 KB Output is correct
60 Correct 35 ms 504 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 42 ms 376 KB Output is correct
63 Correct 39 ms 376 KB Output is correct
64 Correct 58 ms 376 KB Output is correct
65 Correct 6 ms 376 KB Output is correct
66 Correct 6 ms 376 KB Output is correct
67 Correct 13 ms 376 KB Output is correct
68 Correct 26 ms 376 KB Output is correct
69 Correct 37 ms 376 KB Output is correct
70 Correct 35 ms 504 KB Output is correct
71 Correct 3 ms 376 KB Output is correct
72 Correct 39 ms 376 KB Output is correct
73 Correct 38 ms 476 KB Output is correct
74 Correct 36 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 280 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 424 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 8 ms 376 KB Output is correct
29 Correct 8 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 9 ms 376 KB Output is correct
32 Correct 8 ms 376 KB Output is correct
33 Correct 6 ms 376 KB Output is correct
34 Correct 9 ms 380 KB Output is correct
35 Correct 9 ms 416 KB Output is correct
36 Correct 21 ms 376 KB Output is correct
37 Correct 47 ms 384 KB Output is correct
38 Correct 65 ms 504 KB Output is correct
39 Correct 65 ms 396 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 55 ms 376 KB Output is correct
42 Correct 63 ms 376 KB Output is correct
43 Correct 10 ms 376 KB Output is correct
44 Correct 13 ms 376 KB Output is correct
45 Correct 26 ms 376 KB Output is correct
46 Correct 37 ms 376 KB Output is correct
47 Correct 35 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 41 ms 376 KB Output is correct
50 Correct 39 ms 376 KB Output is correct
51 Correct 19 ms 376 KB Output is correct
52 Execution timed out 1061 ms 464 KB Time limit exceeded
53 Halted 0 ms 0 KB -