#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];
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);
}
}
}
memset(dp, false, sizeof(dp));
dp[0][0] = true;
fr(i, 1, N+1){
for(auto j : g[i]){
fr(k, 0, N){
dp[i][k+1] |= dp[j-1][k];
}
}
}
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 = (1<<30)-1;
for(int i = 29; i >= 0; i --){
mask ^= (1<<i);
if(!ok(mask)){
mask ^= (1<<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 |
7 ms |
4300 KB |
Output is correct |
2 |
Correct |
7 ms |
4300 KB |
Output is correct |
3 |
Correct |
7 ms |
4300 KB |
Output is correct |
4 |
Correct |
7 ms |
4312 KB |
Output is correct |
5 |
Correct |
7 ms |
4300 KB |
Output is correct |
6 |
Correct |
7 ms |
4308 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4300 KB |
Output is correct |
9 |
Correct |
7 ms |
4220 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
7 ms |
4308 KB |
Output is correct |
12 |
Correct |
8 ms |
4304 KB |
Output is correct |
13 |
Correct |
9 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
8 ms |
4228 KB |
Output is correct |
16 |
Correct |
8 ms |
4300 KB |
Output is correct |
17 |
Correct |
7 ms |
4300 KB |
Output is correct |
18 |
Correct |
9 ms |
4300 KB |
Output is correct |
19 |
Correct |
7 ms |
4300 KB |
Output is correct |
20 |
Correct |
7 ms |
4304 KB |
Output is correct |
21 |
Correct |
7 ms |
4300 KB |
Output is correct |
22 |
Correct |
7 ms |
4304 KB |
Output is correct |
23 |
Correct |
7 ms |
4300 KB |
Output is correct |
24 |
Correct |
7 ms |
4220 KB |
Output is correct |
25 |
Correct |
7 ms |
4300 KB |
Output is correct |
26 |
Correct |
7 ms |
4300 KB |
Output is correct |
27 |
Correct |
7 ms |
4300 KB |
Output is correct |
28 |
Incorrect |
8 ms |
4308 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4216 KB |
Output is correct |
2 |
Correct |
7 ms |
4300 KB |
Output is correct |
3 |
Correct |
9 ms |
4228 KB |
Output is correct |
4 |
Correct |
7 ms |
4300 KB |
Output is correct |
5 |
Correct |
9 ms |
4300 KB |
Output is correct |
6 |
Correct |
8 ms |
4300 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4224 KB |
Output is correct |
9 |
Correct |
7 ms |
4224 KB |
Output is correct |
10 |
Correct |
7 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4300 KB |
Output is correct |
12 |
Correct |
7 ms |
4300 KB |
Output is correct |
13 |
Correct |
9 ms |
4224 KB |
Output is correct |
14 |
Correct |
8 ms |
4300 KB |
Output is correct |
15 |
Correct |
9 ms |
4312 KB |
Output is correct |
16 |
Correct |
7 ms |
4300 KB |
Output is correct |
17 |
Correct |
7 ms |
4240 KB |
Output is correct |
18 |
Correct |
7 ms |
4300 KB |
Output is correct |
19 |
Correct |
7 ms |
4300 KB |
Output is correct |
20 |
Correct |
8 ms |
4300 KB |
Output is correct |
21 |
Correct |
7 ms |
4300 KB |
Output is correct |
22 |
Correct |
7 ms |
4300 KB |
Output is correct |
23 |
Correct |
7 ms |
4300 KB |
Output is correct |
24 |
Correct |
7 ms |
4300 KB |
Output is correct |
25 |
Correct |
7 ms |
4300 KB |
Output is correct |
26 |
Correct |
7 ms |
4304 KB |
Output is correct |
27 |
Correct |
7 ms |
4300 KB |
Output is correct |
28 |
Correct |
8 ms |
4300 KB |
Output is correct |
29 |
Correct |
8 ms |
4312 KB |
Output is correct |
30 |
Correct |
8 ms |
4300 KB |
Output is correct |
31 |
Correct |
9 ms |
4428 KB |
Output is correct |
32 |
Correct |
8 ms |
4300 KB |
Output is correct |
33 |
Correct |
9 ms |
4300 KB |
Output is correct |
34 |
Correct |
9 ms |
4292 KB |
Output is correct |
35 |
Correct |
8 ms |
4300 KB |
Output is correct |
36 |
Correct |
9 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4304 KB |
Output is correct |
2 |
Correct |
8 ms |
4224 KB |
Output is correct |
3 |
Correct |
7 ms |
4300 KB |
Output is correct |
4 |
Correct |
7 ms |
4300 KB |
Output is correct |
5 |
Correct |
7 ms |
4312 KB |
Output is correct |
6 |
Correct |
8 ms |
4220 KB |
Output is correct |
7 |
Correct |
9 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4308 KB |
Output is correct |
9 |
Correct |
9 ms |
4300 KB |
Output is correct |
10 |
Correct |
7 ms |
4224 KB |
Output is correct |
11 |
Correct |
7 ms |
4300 KB |
Output is correct |
12 |
Correct |
7 ms |
4300 KB |
Output is correct |
13 |
Correct |
7 ms |
4320 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
7 ms |
4304 KB |
Output is correct |
16 |
Correct |
8 ms |
4312 KB |
Output is correct |
17 |
Correct |
8 ms |
4324 KB |
Output is correct |
18 |
Correct |
8 ms |
4300 KB |
Output is correct |
19 |
Correct |
9 ms |
4300 KB |
Output is correct |
20 |
Correct |
9 ms |
4428 KB |
Output is correct |
21 |
Correct |
9 ms |
4312 KB |
Output is correct |
22 |
Correct |
8 ms |
4312 KB |
Output is correct |
23 |
Correct |
9 ms |
4312 KB |
Output is correct |
24 |
Correct |
9 ms |
4312 KB |
Output is correct |
25 |
Correct |
10 ms |
4312 KB |
Output is correct |
26 |
Correct |
11 ms |
4312 KB |
Output is correct |
27 |
Correct |
14 ms |
4352 KB |
Output is correct |
28 |
Correct |
16 ms |
4312 KB |
Output is correct |
29 |
Correct |
15 ms |
4312 KB |
Output is correct |
30 |
Correct |
17 ms |
4312 KB |
Output is correct |
31 |
Correct |
16 ms |
4312 KB |
Output is correct |
32 |
Correct |
16 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4300 KB |
Output is correct |
2 |
Correct |
7 ms |
4300 KB |
Output is correct |
3 |
Correct |
7 ms |
4220 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4312 KB |
Output is correct |
6 |
Correct |
7 ms |
4300 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4300 KB |
Output is correct |
9 |
Correct |
7 ms |
4300 KB |
Output is correct |
10 |
Correct |
7 ms |
4300 KB |
Output is correct |
11 |
Correct |
7 ms |
4308 KB |
Output is correct |
12 |
Correct |
7 ms |
4304 KB |
Output is correct |
13 |
Correct |
7 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Correct |
7 ms |
4300 KB |
Output is correct |
16 |
Correct |
7 ms |
4308 KB |
Output is correct |
17 |
Correct |
8 ms |
4300 KB |
Output is correct |
18 |
Correct |
7 ms |
4300 KB |
Output is correct |
19 |
Correct |
7 ms |
4300 KB |
Output is correct |
20 |
Correct |
8 ms |
4300 KB |
Output is correct |
21 |
Correct |
7 ms |
4300 KB |
Output is correct |
22 |
Correct |
7 ms |
4300 KB |
Output is correct |
23 |
Correct |
8 ms |
4308 KB |
Output is correct |
24 |
Correct |
7 ms |
4300 KB |
Output is correct |
25 |
Correct |
7 ms |
4304 KB |
Output is correct |
26 |
Correct |
7 ms |
4308 KB |
Output is correct |
27 |
Correct |
7 ms |
4312 KB |
Output is correct |
28 |
Incorrect |
7 ms |
4308 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4312 KB |
Output is correct |
2 |
Correct |
8 ms |
4308 KB |
Output is correct |
3 |
Correct |
7 ms |
4300 KB |
Output is correct |
4 |
Correct |
7 ms |
4300 KB |
Output is correct |
5 |
Correct |
7 ms |
4312 KB |
Output is correct |
6 |
Correct |
7 ms |
4300 KB |
Output is correct |
7 |
Correct |
7 ms |
4300 KB |
Output is correct |
8 |
Correct |
7 ms |
4308 KB |
Output is correct |
9 |
Correct |
8 ms |
4308 KB |
Output is correct |
10 |
Correct |
7 ms |
4308 KB |
Output is correct |
11 |
Correct |
7 ms |
4220 KB |
Output is correct |
12 |
Correct |
7 ms |
4304 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
7 ms |
4300 KB |
Output is correct |
15 |
Incorrect |
8 ms |
4300 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |