#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1e9+7;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t z;
const int mxn = 2e3+5;
int N, A, B;
int a[mxn];
vector<int> g[mxn];
//bool dp[mxn][mxn];
bitset<mxn> dp[mxn];
bool ok(ll mask){
fr(i, 0, N){
g[i+1].clear();
ll sum = 0;
for(int j = i; j >= 0; j --){
sum += a[j];
if((mask&sum) == sum){
g[i+1].pb(j+1);
}
}
}
fr(i, 0, N+1) dp[i] = 0;
dp[0][0] = 1;
fr(i, 1, N+1){
for(auto j : g[i]){
dp[i] |= (dp[j-1]<<1);
}
}
bool r = false;
fr(i, A, B+1){
r |= dp[N][i];
}
return r;
}
void solve(){
cin >> N >> A >> B;
fr(i, 0, N){
cin >> a[i];
}
ll mask = (1LL<<41)-1;
for(int i = 40; i >= 0; i --){
mask ^= (1LL<<i);
if(!ok(mask)){
mask ^= (1LL<<i);
}
}
cout<<mask<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
/*
6 1 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
4 ms |
380 KB |
Output is correct |
30 |
Correct |
6 ms |
332 KB |
Output is correct |
31 |
Correct |
8 ms |
400 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
33 |
Correct |
5 ms |
332 KB |
Output is correct |
34 |
Correct |
5 ms |
332 KB |
Output is correct |
35 |
Correct |
5 ms |
332 KB |
Output is correct |
36 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
5 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
332 KB |
Output is correct |
20 |
Correct |
9 ms |
332 KB |
Output is correct |
21 |
Correct |
9 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
332 KB |
Output is correct |
24 |
Correct |
5 ms |
332 KB |
Output is correct |
25 |
Correct |
8 ms |
336 KB |
Output is correct |
26 |
Correct |
12 ms |
408 KB |
Output is correct |
27 |
Correct |
22 ms |
336 KB |
Output is correct |
28 |
Correct |
18 ms |
432 KB |
Output is correct |
29 |
Correct |
17 ms |
432 KB |
Output is correct |
30 |
Correct |
21 ms |
332 KB |
Output is correct |
31 |
Correct |
18 ms |
428 KB |
Output is correct |
32 |
Correct |
18 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
388 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
4 ms |
332 KB |
Output is correct |
40 |
Correct |
4 ms |
332 KB |
Output is correct |
41 |
Correct |
7 ms |
396 KB |
Output is correct |
42 |
Correct |
5 ms |
332 KB |
Output is correct |
43 |
Correct |
7 ms |
356 KB |
Output is correct |
44 |
Correct |
6 ms |
332 KB |
Output is correct |
45 |
Correct |
5 ms |
332 KB |
Output is correct |
46 |
Correct |
5 ms |
332 KB |
Output is correct |
47 |
Correct |
5 ms |
332 KB |
Output is correct |
48 |
Correct |
7 ms |
332 KB |
Output is correct |
49 |
Correct |
12 ms |
416 KB |
Output is correct |
50 |
Correct |
15 ms |
428 KB |
Output is correct |
51 |
Correct |
17 ms |
332 KB |
Output is correct |
52 |
Correct |
17 ms |
436 KB |
Output is correct |
53 |
Correct |
18 ms |
332 KB |
Output is correct |
54 |
Correct |
22 ms |
428 KB |
Output is correct |
55 |
Correct |
25 ms |
332 KB |
Output is correct |
56 |
Correct |
2 ms |
332 KB |
Output is correct |
57 |
Correct |
6 ms |
332 KB |
Output is correct |
58 |
Correct |
5 ms |
332 KB |
Output is correct |
59 |
Correct |
6 ms |
332 KB |
Output is correct |
60 |
Correct |
5 ms |
332 KB |
Output is correct |
61 |
Correct |
5 ms |
332 KB |
Output is correct |
62 |
Correct |
7 ms |
332 KB |
Output is correct |
63 |
Correct |
7 ms |
432 KB |
Output is correct |
64 |
Correct |
16 ms |
428 KB |
Output is correct |
65 |
Correct |
2 ms |
336 KB |
Output is correct |
66 |
Correct |
3 ms |
332 KB |
Output is correct |
67 |
Correct |
5 ms |
332 KB |
Output is correct |
68 |
Correct |
4 ms |
332 KB |
Output is correct |
69 |
Correct |
7 ms |
332 KB |
Output is correct |
70 |
Correct |
4 ms |
332 KB |
Output is correct |
71 |
Correct |
5 ms |
332 KB |
Output is correct |
72 |
Correct |
7 ms |
432 KB |
Output is correct |
73 |
Correct |
7 ms |
332 KB |
Output is correct |
74 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
4 ms |
392 KB |
Output is correct |
28 |
Correct |
5 ms |
332 KB |
Output is correct |
29 |
Correct |
5 ms |
332 KB |
Output is correct |
30 |
Correct |
5 ms |
332 KB |
Output is correct |
31 |
Correct |
5 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
396 KB |
Output is correct |
33 |
Correct |
9 ms |
332 KB |
Output is correct |
34 |
Correct |
5 ms |
392 KB |
Output is correct |
35 |
Correct |
12 ms |
400 KB |
Output is correct |
36 |
Correct |
16 ms |
420 KB |
Output is correct |
37 |
Correct |
15 ms |
332 KB |
Output is correct |
38 |
Correct |
23 ms |
424 KB |
Output is correct |
39 |
Correct |
17 ms |
416 KB |
Output is correct |
40 |
Correct |
19 ms |
332 KB |
Output is correct |
41 |
Correct |
22 ms |
412 KB |
Output is correct |
42 |
Correct |
19 ms |
432 KB |
Output is correct |
43 |
Correct |
2 ms |
332 KB |
Output is correct |
44 |
Correct |
4 ms |
332 KB |
Output is correct |
45 |
Correct |
5 ms |
336 KB |
Output is correct |
46 |
Correct |
7 ms |
332 KB |
Output is correct |
47 |
Correct |
4 ms |
336 KB |
Output is correct |
48 |
Correct |
5 ms |
332 KB |
Output is correct |
49 |
Correct |
7 ms |
432 KB |
Output is correct |
50 |
Correct |
7 ms |
332 KB |
Output is correct |
51 |
Correct |
5 ms |
332 KB |
Output is correct |
52 |
Correct |
121 ms |
1456 KB |
Output is correct |
53 |
Correct |
153 ms |
2196 KB |
Output is correct |
54 |
Correct |
256 ms |
3276 KB |
Output is correct |
55 |
Correct |
228 ms |
3276 KB |
Output is correct |
56 |
Correct |
664 ms |
11468 KB |
Output is correct |
57 |
Correct |
644 ms |
11536 KB |
Output is correct |
58 |
Correct |
451 ms |
11476 KB |
Output is correct |
59 |
Correct |
462 ms |
11496 KB |
Output is correct |
60 |
Correct |
785 ms |
11480 KB |
Output is correct |
61 |
Correct |
7 ms |
332 KB |
Output is correct |
62 |
Correct |
138 ms |
2124 KB |
Output is correct |
63 |
Correct |
241 ms |
3280 KB |
Output is correct |
64 |
Correct |
205 ms |
3396 KB |
Output is correct |
65 |
Correct |
334 ms |
6536 KB |
Output is correct |
66 |
Correct |
463 ms |
9388 KB |
Output is correct |
67 |
Correct |
644 ms |
11592 KB |
Output is correct |
68 |
Correct |
650 ms |
11480 KB |
Output is correct |
69 |
Correct |
570 ms |
11480 KB |
Output is correct |