#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
ll n,a,b;
vi y;
ll fewest(ll forbiddenBits){
//cout<<forbiddenBits<<": "<<endl;
vi dp(n+1,0); //dp[index];
dp[n] = 0;
for(ll i = n-1;i>=0;--i){
dp[i] = 1e18;
ll sum = 0;
rep(j,i+1,n+1){
sum += y[j-1];
if((sum&forbiddenBits)==0)
dp[i] = min(dp[i],dp[j]+1);
}
}
return dp[0];
}
bool possible(ll forbiddenBits){
//cout<<forbiddenBits<<": "<<endl;
if(a==1) return fewest(forbiddenBits)<=b;
vector<vector<bool> > dp(n+1,vector<bool>(n+1,false)); //dp[numGroups][index];
rep(i,a,b+1) dp[i][n] = true;
for(ll i = n-1;i>=0;--i){
rep(numGroups,0,n){
ll sum = 0;
rep(j,i+1,n+1){
sum += y[j-1];
dp[numGroups][i] = (dp[numGroups][i]|(((sum&forbiddenBits)==0)&&(dp[numGroups+1][j])));
}
//cout<<dp[numGroups][i];
}
// cout<<endl;
}
return dp[0][0];
}
int main(){
cin.sync_with_stdio(false);
cin>>n>>a>>b;
y.resize(n);
rep(i,0,n) cin>>y[i];
ll ans = 0;
ll forbiddenBits = 0;
for(ll i = 60; i>=0;--i){
forbiddenBits |= (1LL<<i);
if(!possible(forbiddenBits))
forbiddenBits ^= (1LL<<i);
//cout<<((forbiddenBits&(1LL<<i))>0);
if(!(forbiddenBits&(1LL<<i)))
ans |= (1LL<<i);
}
//cout<<endl;
cout<<ans<<endl;
//cout<<possible(2305843009213693942ll)<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
560 KB |
Output is correct |
4 |
Correct |
3 ms |
560 KB |
Output is correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Correct |
2 ms |
580 KB |
Output is correct |
7 |
Correct |
3 ms |
580 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
2 ms |
696 KB |
Output is correct |
10 |
Correct |
2 ms |
696 KB |
Output is correct |
11 |
Correct |
3 ms |
696 KB |
Output is correct |
12 |
Correct |
3 ms |
696 KB |
Output is correct |
13 |
Correct |
3 ms |
696 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
4 ms |
696 KB |
Output is correct |
16 |
Correct |
3 ms |
696 KB |
Output is correct |
17 |
Correct |
3 ms |
696 KB |
Output is correct |
18 |
Correct |
3 ms |
696 KB |
Output is correct |
19 |
Correct |
4 ms |
696 KB |
Output is correct |
20 |
Correct |
4 ms |
696 KB |
Output is correct |
21 |
Correct |
5 ms |
696 KB |
Output is correct |
22 |
Correct |
6 ms |
696 KB |
Output is correct |
23 |
Correct |
5 ms |
696 KB |
Output is correct |
24 |
Correct |
3 ms |
696 KB |
Output is correct |
25 |
Correct |
5 ms |
696 KB |
Output is correct |
26 |
Correct |
5 ms |
696 KB |
Output is correct |
27 |
Correct |
2 ms |
696 KB |
Output is correct |
28 |
Correct |
3 ms |
696 KB |
Output is correct |
29 |
Correct |
3 ms |
696 KB |
Output is correct |
30 |
Correct |
3 ms |
696 KB |
Output is correct |
31 |
Correct |
2 ms |
696 KB |
Output is correct |
32 |
Correct |
3 ms |
696 KB |
Output is correct |
33 |
Correct |
3 ms |
736 KB |
Output is correct |
34 |
Correct |
2 ms |
736 KB |
Output is correct |
35 |
Correct |
2 ms |
736 KB |
Output is correct |
36 |
Correct |
2 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
736 KB |
Output is correct |
2 |
Correct |
3 ms |
736 KB |
Output is correct |
3 |
Correct |
3 ms |
736 KB |
Output is correct |
4 |
Correct |
3 ms |
736 KB |
Output is correct |
5 |
Correct |
3 ms |
736 KB |
Output is correct |
6 |
Correct |
3 ms |
736 KB |
Output is correct |
7 |
Correct |
3 ms |
736 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
3 ms |
736 KB |
Output is correct |
10 |
Correct |
3 ms |
756 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
756 KB |
Output is correct |
13 |
Correct |
2 ms |
756 KB |
Output is correct |
14 |
Correct |
3 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
756 KB |
Output is correct |
17 |
Correct |
3 ms |
756 KB |
Output is correct |
18 |
Correct |
3 ms |
756 KB |
Output is correct |
19 |
Correct |
3 ms |
756 KB |
Output is correct |
20 |
Correct |
3 ms |
756 KB |
Output is correct |
21 |
Correct |
4 ms |
756 KB |
Output is correct |
22 |
Correct |
3 ms |
756 KB |
Output is correct |
23 |
Correct |
4 ms |
756 KB |
Output is correct |
24 |
Correct |
4 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
5 ms |
756 KB |
Output is correct |
27 |
Correct |
3 ms |
756 KB |
Output is correct |
28 |
Correct |
3 ms |
756 KB |
Output is correct |
29 |
Correct |
4 ms |
756 KB |
Output is correct |
30 |
Correct |
3 ms |
756 KB |
Output is correct |
31 |
Correct |
3 ms |
756 KB |
Output is correct |
32 |
Correct |
3 ms |
756 KB |
Output is correct |
33 |
Correct |
2 ms |
756 KB |
Output is correct |
34 |
Correct |
3 ms |
756 KB |
Output is correct |
35 |
Correct |
2 ms |
756 KB |
Output is correct |
36 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
756 KB |
Output is correct |
2 |
Correct |
3 ms |
756 KB |
Output is correct |
3 |
Correct |
3 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
756 KB |
Output is correct |
9 |
Correct |
3 ms |
756 KB |
Output is correct |
10 |
Correct |
3 ms |
756 KB |
Output is correct |
11 |
Correct |
3 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
756 KB |
Output is correct |
13 |
Correct |
3 ms |
756 KB |
Output is correct |
14 |
Correct |
2 ms |
756 KB |
Output is correct |
15 |
Correct |
3 ms |
756 KB |
Output is correct |
16 |
Correct |
4 ms |
756 KB |
Output is correct |
17 |
Correct |
3 ms |
756 KB |
Output is correct |
18 |
Correct |
2 ms |
756 KB |
Output is correct |
19 |
Correct |
3 ms |
756 KB |
Output is correct |
20 |
Correct |
4 ms |
756 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
3 ms |
756 KB |
Output is correct |
23 |
Correct |
3 ms |
756 KB |
Output is correct |
24 |
Correct |
4 ms |
756 KB |
Output is correct |
25 |
Correct |
3 ms |
756 KB |
Output is correct |
26 |
Correct |
3 ms |
756 KB |
Output is correct |
27 |
Correct |
3 ms |
756 KB |
Output is correct |
28 |
Correct |
4 ms |
756 KB |
Output is correct |
29 |
Correct |
3 ms |
756 KB |
Output is correct |
30 |
Correct |
4 ms |
756 KB |
Output is correct |
31 |
Correct |
3 ms |
756 KB |
Output is correct |
32 |
Correct |
4 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
756 KB |
Output is correct |
2 |
Correct |
3 ms |
756 KB |
Output is correct |
3 |
Correct |
2 ms |
756 KB |
Output is correct |
4 |
Correct |
3 ms |
756 KB |
Output is correct |
5 |
Correct |
4 ms |
756 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
756 KB |
Output is correct |
9 |
Correct |
3 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
756 KB |
Output is correct |
11 |
Correct |
4 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
756 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
3 ms |
760 KB |
Output is correct |
15 |
Correct |
3 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
3 ms |
760 KB |
Output is correct |
18 |
Correct |
3 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
760 KB |
Output is correct |
20 |
Correct |
3 ms |
760 KB |
Output is correct |
21 |
Correct |
4 ms |
760 KB |
Output is correct |
22 |
Correct |
3 ms |
760 KB |
Output is correct |
23 |
Correct |
3 ms |
760 KB |
Output is correct |
24 |
Correct |
4 ms |
760 KB |
Output is correct |
25 |
Correct |
4 ms |
760 KB |
Output is correct |
26 |
Correct |
4 ms |
760 KB |
Output is correct |
27 |
Correct |
2 ms |
760 KB |
Output is correct |
28 |
Correct |
2 ms |
760 KB |
Output is correct |
29 |
Correct |
3 ms |
760 KB |
Output is correct |
30 |
Correct |
3 ms |
760 KB |
Output is correct |
31 |
Correct |
2 ms |
760 KB |
Output is correct |
32 |
Correct |
3 ms |
760 KB |
Output is correct |
33 |
Correct |
3 ms |
760 KB |
Output is correct |
34 |
Correct |
4 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
760 KB |
Output is correct |
36 |
Correct |
3 ms |
760 KB |
Output is correct |
37 |
Correct |
2 ms |
760 KB |
Output is correct |
38 |
Correct |
2 ms |
760 KB |
Output is correct |
39 |
Correct |
3 ms |
760 KB |
Output is correct |
40 |
Correct |
3 ms |
760 KB |
Output is correct |
41 |
Correct |
2 ms |
760 KB |
Output is correct |
42 |
Correct |
3 ms |
760 KB |
Output is correct |
43 |
Correct |
3 ms |
760 KB |
Output is correct |
44 |
Correct |
3 ms |
760 KB |
Output is correct |
45 |
Correct |
3 ms |
760 KB |
Output is correct |
46 |
Correct |
3 ms |
760 KB |
Output is correct |
47 |
Correct |
3 ms |
760 KB |
Output is correct |
48 |
Correct |
4 ms |
760 KB |
Output is correct |
49 |
Correct |
3 ms |
760 KB |
Output is correct |
50 |
Correct |
3 ms |
760 KB |
Output is correct |
51 |
Correct |
4 ms |
760 KB |
Output is correct |
52 |
Correct |
3 ms |
760 KB |
Output is correct |
53 |
Correct |
5 ms |
760 KB |
Output is correct |
54 |
Correct |
3 ms |
760 KB |
Output is correct |
55 |
Correct |
3 ms |
760 KB |
Output is correct |
56 |
Correct |
3 ms |
760 KB |
Output is correct |
57 |
Correct |
3 ms |
760 KB |
Output is correct |
58 |
Correct |
3 ms |
760 KB |
Output is correct |
59 |
Correct |
4 ms |
760 KB |
Output is correct |
60 |
Correct |
3 ms |
760 KB |
Output is correct |
61 |
Correct |
3 ms |
760 KB |
Output is correct |
62 |
Correct |
3 ms |
760 KB |
Output is correct |
63 |
Correct |
4 ms |
760 KB |
Output is correct |
64 |
Correct |
75 ms |
760 KB |
Output is correct |
65 |
Correct |
16 ms |
760 KB |
Output is correct |
66 |
Correct |
28 ms |
760 KB |
Output is correct |
67 |
Correct |
47 ms |
760 KB |
Output is correct |
68 |
Correct |
80 ms |
760 KB |
Output is correct |
69 |
Correct |
100 ms |
760 KB |
Output is correct |
70 |
Correct |
97 ms |
764 KB |
Output is correct |
71 |
Correct |
97 ms |
764 KB |
Output is correct |
72 |
Correct |
112 ms |
764 KB |
Output is correct |
73 |
Correct |
103 ms |
764 KB |
Output is correct |
74 |
Correct |
109 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
884 KB |
Output is correct |
2 |
Correct |
3 ms |
884 KB |
Output is correct |
3 |
Correct |
2 ms |
884 KB |
Output is correct |
4 |
Correct |
3 ms |
884 KB |
Output is correct |
5 |
Correct |
3 ms |
884 KB |
Output is correct |
6 |
Correct |
3 ms |
884 KB |
Output is correct |
7 |
Correct |
4 ms |
884 KB |
Output is correct |
8 |
Correct |
3 ms |
884 KB |
Output is correct |
9 |
Correct |
3 ms |
884 KB |
Output is correct |
10 |
Correct |
2 ms |
884 KB |
Output is correct |
11 |
Correct |
2 ms |
884 KB |
Output is correct |
12 |
Correct |
3 ms |
884 KB |
Output is correct |
13 |
Correct |
3 ms |
884 KB |
Output is correct |
14 |
Correct |
2 ms |
884 KB |
Output is correct |
15 |
Correct |
3 ms |
884 KB |
Output is correct |
16 |
Correct |
3 ms |
884 KB |
Output is correct |
17 |
Correct |
2 ms |
884 KB |
Output is correct |
18 |
Correct |
3 ms |
884 KB |
Output is correct |
19 |
Correct |
3 ms |
884 KB |
Output is correct |
20 |
Correct |
3 ms |
884 KB |
Output is correct |
21 |
Correct |
3 ms |
884 KB |
Output is correct |
22 |
Correct |
3 ms |
884 KB |
Output is correct |
23 |
Correct |
2 ms |
884 KB |
Output is correct |
24 |
Correct |
3 ms |
884 KB |
Output is correct |
25 |
Correct |
3 ms |
884 KB |
Output is correct |
26 |
Correct |
3 ms |
884 KB |
Output is correct |
27 |
Correct |
3 ms |
884 KB |
Output is correct |
28 |
Correct |
4 ms |
884 KB |
Output is correct |
29 |
Correct |
1 ms |
884 KB |
Output is correct |
30 |
Correct |
2 ms |
884 KB |
Output is correct |
31 |
Correct |
3 ms |
884 KB |
Output is correct |
32 |
Correct |
3 ms |
884 KB |
Output is correct |
33 |
Correct |
4 ms |
884 KB |
Output is correct |
34 |
Correct |
4 ms |
884 KB |
Output is correct |
35 |
Correct |
3 ms |
884 KB |
Output is correct |
36 |
Correct |
4 ms |
884 KB |
Output is correct |
37 |
Correct |
3 ms |
884 KB |
Output is correct |
38 |
Correct |
3 ms |
884 KB |
Output is correct |
39 |
Correct |
4 ms |
884 KB |
Output is correct |
40 |
Correct |
4 ms |
884 KB |
Output is correct |
41 |
Correct |
3 ms |
884 KB |
Output is correct |
42 |
Correct |
3 ms |
884 KB |
Output is correct |
43 |
Correct |
3 ms |
884 KB |
Output is correct |
44 |
Correct |
5 ms |
884 KB |
Output is correct |
45 |
Correct |
4 ms |
884 KB |
Output is correct |
46 |
Correct |
4 ms |
884 KB |
Output is correct |
47 |
Correct |
3 ms |
884 KB |
Output is correct |
48 |
Correct |
3 ms |
884 KB |
Output is correct |
49 |
Correct |
4 ms |
884 KB |
Output is correct |
50 |
Correct |
4 ms |
884 KB |
Output is correct |
51 |
Correct |
4 ms |
884 KB |
Output is correct |
52 |
Correct |
24 ms |
884 KB |
Output is correct |
53 |
Correct |
39 ms |
884 KB |
Output is correct |
54 |
Correct |
79 ms |
884 KB |
Output is correct |
55 |
Correct |
63 ms |
884 KB |
Output is correct |
56 |
Correct |
241 ms |
884 KB |
Output is correct |
57 |
Correct |
234 ms |
928 KB |
Output is correct |
58 |
Correct |
256 ms |
952 KB |
Output is correct |
59 |
Correct |
225 ms |
952 KB |
Output is correct |
60 |
Correct |
247 ms |
952 KB |
Output is correct |
61 |
Correct |
3 ms |
952 KB |
Output is correct |
62 |
Correct |
35 ms |
1056 KB |
Output is correct |
63 |
Correct |
66 ms |
1056 KB |
Output is correct |
64 |
Correct |
62 ms |
1056 KB |
Output is correct |
65 |
Correct |
131 ms |
1100 KB |
Output is correct |
66 |
Correct |
172 ms |
1100 KB |
Output is correct |
67 |
Correct |
231 ms |
1136 KB |
Output is correct |
68 |
Correct |
242 ms |
1156 KB |
Output is correct |
69 |
Correct |
227 ms |
1156 KB |
Output is correct |