Submission #527588

# Submission time Handle Problem Language Result Execution time Memory
527588 2022-02-17T17:37:03 Z SlavicG Bali Sculptures (APIO15_sculpture) C++17
71 / 100
1000 ms 16160 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 2005;
ll p[N];
ll sum(int l, int r) {
    return p[r] - (l ? p[l - 1] : 0);
}

//dp[index][OR][number of subarrays] = 1 if possible to obtain such partition

int dp[N][N];
ll excluded;

bool check(ll k, int n, vector<ll>& a, int A, int B) {
    for(int i = 0;i < N; ++i) for(int j = 0;j < N; ++j) dp[i][j] = 0;
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0;j < i; ++j) {
            ll s = sum(j, i - 1);
            if((s & excluded) || (s & (1LL << k))) continue;
            for(int x = 0;x < n; ++x) {
                dp[i][x + 1] |= dp[j][x];
            }
        }
    }
    for(int j = A; j <= B; ++j) {
        if(dp[n][j]) return true;
    }
    return false;
}

void solve() { 
    ll n, A, B;
    cin >> n >> A >> B;
    vector<ll> a(n);
    for(int i = 0;i < n; ++i) {
        cin >> a[i];
        p[i] = (i ? p[i - 1] : 0) + a[i];
    }

    ll ans = 0;
    for(ll pw = 62; pw >= 0; --pw) {
        if(check(pw, n, a, A, B)) {
            excluded += (1LL << pw);
        } else {
            ans += (1LL << pw);
        }
    }
    cout << ans << "\n";
} 
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 16024 KB Output is correct
2 Correct 123 ms 16024 KB Output is correct
3 Correct 115 ms 16028 KB Output is correct
4 Correct 109 ms 15948 KB Output is correct
5 Correct 116 ms 15928 KB Output is correct
6 Correct 123 ms 16028 KB Output is correct
7 Correct 126 ms 16028 KB Output is correct
8 Correct 114 ms 16028 KB Output is correct
9 Correct 107 ms 16028 KB Output is correct
10 Correct 109 ms 16028 KB Output is correct
11 Correct 116 ms 16032 KB Output is correct
12 Correct 118 ms 16028 KB Output is correct
13 Correct 109 ms 16036 KB Output is correct
14 Correct 111 ms 16028 KB Output is correct
15 Correct 112 ms 16032 KB Output is correct
16 Correct 119 ms 16068 KB Output is correct
17 Correct 109 ms 16016 KB Output is correct
18 Correct 110 ms 16024 KB Output is correct
19 Correct 112 ms 15948 KB Output is correct
20 Correct 113 ms 16024 KB Output is correct
21 Correct 115 ms 16076 KB Output is correct
22 Correct 107 ms 16032 KB Output is correct
23 Correct 107 ms 16028 KB Output is correct
24 Correct 121 ms 15948 KB Output is correct
25 Correct 112 ms 16024 KB Output is correct
26 Correct 112 ms 16024 KB Output is correct
27 Correct 108 ms 16024 KB Output is correct
28 Correct 116 ms 16028 KB Output is correct
29 Correct 113 ms 16032 KB Output is correct
30 Correct 109 ms 16044 KB Output is correct
31 Correct 106 ms 16040 KB Output is correct
32 Correct 106 ms 15948 KB Output is correct
33 Correct 107 ms 16036 KB Output is correct
34 Correct 108 ms 16036 KB Output is correct
35 Correct 111 ms 15948 KB Output is correct
36 Correct 111 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 16028 KB Output is correct
2 Correct 110 ms 16028 KB Output is correct
3 Correct 116 ms 16028 KB Output is correct
4 Correct 117 ms 16068 KB Output is correct
5 Correct 112 ms 16028 KB Output is correct
6 Correct 106 ms 16028 KB Output is correct
7 Correct 111 ms 15948 KB Output is correct
8 Correct 116 ms 16032 KB Output is correct
9 Correct 110 ms 16028 KB Output is correct
10 Correct 113 ms 16024 KB Output is correct
11 Correct 110 ms 16024 KB Output is correct
12 Correct 108 ms 16032 KB Output is correct
13 Correct 111 ms 16032 KB Output is correct
14 Correct 124 ms 16024 KB Output is correct
15 Correct 108 ms 16024 KB Output is correct
16 Correct 109 ms 16024 KB Output is correct
17 Correct 110 ms 15948 KB Output is correct
18 Correct 127 ms 15948 KB Output is correct
19 Correct 115 ms 15948 KB Output is correct
20 Correct 120 ms 16028 KB Output is correct
21 Correct 123 ms 16024 KB Output is correct
22 Correct 116 ms 15952 KB Output is correct
23 Correct 107 ms 15948 KB Output is correct
24 Correct 118 ms 16032 KB Output is correct
25 Correct 112 ms 16028 KB Output is correct
26 Correct 122 ms 16032 KB Output is correct
27 Correct 108 ms 15948 KB Output is correct
28 Correct 109 ms 16032 KB Output is correct
29 Correct 116 ms 15948 KB Output is correct
30 Correct 110 ms 16028 KB Output is correct
31 Correct 114 ms 16068 KB Output is correct
32 Correct 111 ms 16028 KB Output is correct
33 Correct 113 ms 15928 KB Output is correct
34 Correct 112 ms 15948 KB Output is correct
35 Correct 114 ms 16032 KB Output is correct
36 Correct 112 ms 16024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 16024 KB Output is correct
2 Correct 125 ms 15948 KB Output is correct
3 Correct 111 ms 16028 KB Output is correct
4 Correct 113 ms 16036 KB Output is correct
5 Correct 109 ms 16032 KB Output is correct
6 Correct 124 ms 15948 KB Output is correct
7 Correct 109 ms 15948 KB Output is correct
8 Correct 118 ms 16036 KB Output is correct
9 Correct 117 ms 16024 KB Output is correct
10 Correct 108 ms 16024 KB Output is correct
11 Correct 110 ms 16028 KB Output is correct
12 Correct 122 ms 16032 KB Output is correct
13 Correct 121 ms 15948 KB Output is correct
14 Correct 106 ms 16024 KB Output is correct
15 Correct 109 ms 16028 KB Output is correct
16 Correct 106 ms 16036 KB Output is correct
17 Correct 110 ms 16044 KB Output is correct
18 Correct 133 ms 16044 KB Output is correct
19 Correct 116 ms 15960 KB Output is correct
20 Correct 110 ms 16040 KB Output is correct
21 Correct 110 ms 16040 KB Output is correct
22 Correct 112 ms 15960 KB Output is correct
23 Correct 125 ms 16040 KB Output is correct
24 Correct 117 ms 16044 KB Output is correct
25 Correct 121 ms 15948 KB Output is correct
26 Correct 124 ms 16024 KB Output is correct
27 Correct 131 ms 16028 KB Output is correct
28 Correct 129 ms 16028 KB Output is correct
29 Correct 123 ms 15948 KB Output is correct
30 Correct 126 ms 15948 KB Output is correct
31 Correct 131 ms 15948 KB Output is correct
32 Correct 127 ms 16024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 16024 KB Output is correct
2 Correct 123 ms 16028 KB Output is correct
3 Correct 109 ms 15948 KB Output is correct
4 Correct 109 ms 16028 KB Output is correct
5 Correct 118 ms 16068 KB Output is correct
6 Correct 119 ms 16024 KB Output is correct
7 Correct 120 ms 16008 KB Output is correct
8 Correct 126 ms 16024 KB Output is correct
9 Correct 114 ms 15948 KB Output is correct
10 Correct 122 ms 16024 KB Output is correct
11 Correct 113 ms 16028 KB Output is correct
12 Correct 123 ms 16028 KB Output is correct
13 Correct 110 ms 16068 KB Output is correct
14 Correct 116 ms 16024 KB Output is correct
15 Correct 110 ms 15948 KB Output is correct
16 Correct 110 ms 16028 KB Output is correct
17 Correct 108 ms 15948 KB Output is correct
18 Correct 119 ms 16028 KB Output is correct
19 Correct 115 ms 16028 KB Output is correct
20 Correct 110 ms 15948 KB Output is correct
21 Correct 125 ms 15948 KB Output is correct
22 Correct 110 ms 16024 KB Output is correct
23 Correct 108 ms 16036 KB Output is correct
24 Correct 108 ms 16024 KB Output is correct
25 Correct 105 ms 16028 KB Output is correct
26 Correct 108 ms 15948 KB Output is correct
27 Correct 112 ms 16028 KB Output is correct
28 Correct 119 ms 16028 KB Output is correct
29 Correct 116 ms 16060 KB Output is correct
30 Correct 108 ms 15948 KB Output is correct
31 Correct 108 ms 15948 KB Output is correct
32 Correct 111 ms 16032 KB Output is correct
33 Correct 114 ms 16036 KB Output is correct
34 Correct 112 ms 15936 KB Output is correct
35 Correct 110 ms 16028 KB Output is correct
36 Correct 108 ms 16028 KB Output is correct
37 Correct 120 ms 15948 KB Output is correct
38 Correct 113 ms 16032 KB Output is correct
39 Correct 112 ms 15940 KB Output is correct
40 Correct 109 ms 16032 KB Output is correct
41 Correct 113 ms 16028 KB Output is correct
42 Correct 115 ms 16032 KB Output is correct
43 Correct 115 ms 15948 KB Output is correct
44 Correct 114 ms 16032 KB Output is correct
45 Correct 110 ms 16036 KB Output is correct
46 Correct 110 ms 16068 KB Output is correct
47 Correct 114 ms 15948 KB Output is correct
48 Correct 120 ms 15932 KB Output is correct
49 Correct 120 ms 16036 KB Output is correct
50 Correct 121 ms 15948 KB Output is correct
51 Correct 132 ms 16032 KB Output is correct
52 Correct 140 ms 16032 KB Output is correct
53 Correct 124 ms 16032 KB Output is correct
54 Correct 136 ms 15984 KB Output is correct
55 Correct 133 ms 16032 KB Output is correct
56 Correct 119 ms 15948 KB Output is correct
57 Correct 112 ms 16032 KB Output is correct
58 Correct 118 ms 16028 KB Output is correct
59 Correct 117 ms 16000 KB Output is correct
60 Correct 119 ms 16160 KB Output is correct
61 Correct 120 ms 15948 KB Output is correct
62 Correct 120 ms 16044 KB Output is correct
63 Correct 120 ms 16032 KB Output is correct
64 Correct 130 ms 16044 KB Output is correct
65 Correct 112 ms 15948 KB Output is correct
66 Correct 110 ms 15948 KB Output is correct
67 Correct 115 ms 16028 KB Output is correct
68 Correct 114 ms 16044 KB Output is correct
69 Correct 119 ms 16032 KB Output is correct
70 Correct 123 ms 15932 KB Output is correct
71 Correct 124 ms 15948 KB Output is correct
72 Correct 120 ms 15948 KB Output is correct
73 Correct 143 ms 16032 KB Output is correct
74 Correct 122 ms 16028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 16024 KB Output is correct
2 Correct 123 ms 15948 KB Output is correct
3 Correct 113 ms 16028 KB Output is correct
4 Correct 114 ms 16036 KB Output is correct
5 Correct 124 ms 16028 KB Output is correct
6 Correct 111 ms 15948 KB Output is correct
7 Correct 106 ms 16028 KB Output is correct
8 Correct 123 ms 16032 KB Output is correct
9 Correct 122 ms 15948 KB Output is correct
10 Correct 108 ms 15948 KB Output is correct
11 Correct 106 ms 15948 KB Output is correct
12 Correct 107 ms 16032 KB Output is correct
13 Correct 113 ms 15984 KB Output is correct
14 Correct 119 ms 15980 KB Output is correct
15 Correct 114 ms 15948 KB Output is correct
16 Correct 109 ms 16028 KB Output is correct
17 Correct 124 ms 16036 KB Output is correct
18 Correct 108 ms 15948 KB Output is correct
19 Correct 107 ms 15932 KB Output is correct
20 Correct 113 ms 16028 KB Output is correct
21 Correct 120 ms 15948 KB Output is correct
22 Correct 107 ms 16032 KB Output is correct
23 Correct 111 ms 16032 KB Output is correct
24 Correct 116 ms 16036 KB Output is correct
25 Correct 111 ms 16032 KB Output is correct
26 Correct 107 ms 16036 KB Output is correct
27 Correct 113 ms 16028 KB Output is correct
28 Correct 121 ms 16044 KB Output is correct
29 Correct 111 ms 16032 KB Output is correct
30 Correct 110 ms 15948 KB Output is correct
31 Correct 124 ms 16036 KB Output is correct
32 Correct 116 ms 16028 KB Output is correct
33 Correct 111 ms 15948 KB Output is correct
34 Correct 110 ms 15948 KB Output is correct
35 Correct 111 ms 15948 KB Output is correct
36 Correct 116 ms 16028 KB Output is correct
37 Correct 126 ms 16044 KB Output is correct
38 Correct 127 ms 16036 KB Output is correct
39 Correct 147 ms 16032 KB Output is correct
40 Correct 125 ms 16032 KB Output is correct
41 Correct 143 ms 16076 KB Output is correct
42 Correct 130 ms 16036 KB Output is correct
43 Correct 110 ms 16028 KB Output is correct
44 Correct 128 ms 16036 KB Output is correct
45 Correct 115 ms 16028 KB Output is correct
46 Correct 133 ms 15948 KB Output is correct
47 Correct 116 ms 16036 KB Output is correct
48 Correct 132 ms 16032 KB Output is correct
49 Correct 127 ms 15948 KB Output is correct
50 Correct 136 ms 16076 KB Output is correct
51 Correct 121 ms 16032 KB Output is correct
52 Execution timed out 1085 ms 15948 KB Time limit exceeded
53 Halted 0 ms 0 KB -