#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2100, LOG = 40, INF = 1e9;
ll ps[N], n, A, B;
bool dp[N][N];
int pd[N];
bool good(ll vl, int k, ll res){
if(((vl | res) - res) < (1LL << k))return true;
return false;
}
bool check(int k, ll res){
dp[0][0] = true;
for(int i=1; i<=n; i++)
dp[i][0] = false;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
dp[i][j] = false;
for(int t=i-1; t>=0; t--)
if(good(ps[i] - ps[t], k, res))
dp[i][j] |= dp[t][j - 1];
}
}
for(int i=A; i<=B; i++)
if(dp[n][i])return true;
return false;
}
bool check2(int k, ll res){
pd[0] = 0;
for(int i=1; i<=n; i++){
pd[i] = INF;
for(int t=i-1; t>=0; t--)
if(good(ps[i] - ps[t], k, res))
pd[i] = min(pd[i], pd[t] + 1);
}
if(pd[n] <= B)return true;
return false;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> A >> B;
for(int i=0; i<n; i++){
int x; cin >> x;
ps[i + 1] = ps[i] + x;
}
ll res = 0;
for(int i=LOG-1; i>=0; i--){
if(n < 110){
if(!check(i, res))res += (1LL << i);
}else{
if(!check2(i, res))res += (1LL << i);
}
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6512 KB |
Output is correct |
2 |
Correct |
0 ms |
6512 KB |
Output is correct |
3 |
Correct |
0 ms |
6512 KB |
Output is correct |
4 |
Correct |
0 ms |
6512 KB |
Output is correct |
5 |
Correct |
0 ms |
6512 KB |
Output is correct |
6 |
Correct |
0 ms |
6512 KB |
Output is correct |
7 |
Correct |
0 ms |
6512 KB |
Output is correct |
8 |
Correct |
0 ms |
6512 KB |
Output is correct |
9 |
Correct |
0 ms |
6512 KB |
Output is correct |
10 |
Correct |
0 ms |
6512 KB |
Output is correct |
11 |
Correct |
0 ms |
6512 KB |
Output is correct |
12 |
Correct |
0 ms |
6512 KB |
Output is correct |
13 |
Correct |
0 ms |
6512 KB |
Output is correct |
14 |
Correct |
0 ms |
6512 KB |
Output is correct |
15 |
Correct |
0 ms |
6512 KB |
Output is correct |
16 |
Correct |
0 ms |
6512 KB |
Output is correct |
17 |
Correct |
0 ms |
6512 KB |
Output is correct |
18 |
Correct |
0 ms |
6512 KB |
Output is correct |
19 |
Correct |
0 ms |
6512 KB |
Output is correct |
20 |
Correct |
0 ms |
6512 KB |
Output is correct |
21 |
Correct |
0 ms |
6512 KB |
Output is correct |
22 |
Correct |
0 ms |
6512 KB |
Output is correct |
23 |
Correct |
0 ms |
6512 KB |
Output is correct |
24 |
Correct |
0 ms |
6512 KB |
Output is correct |
25 |
Correct |
0 ms |
6512 KB |
Output is correct |
26 |
Correct |
0 ms |
6512 KB |
Output is correct |
27 |
Correct |
0 ms |
6512 KB |
Output is correct |
28 |
Correct |
0 ms |
6512 KB |
Output is correct |
29 |
Correct |
0 ms |
6512 KB |
Output is correct |
30 |
Correct |
0 ms |
6512 KB |
Output is correct |
31 |
Correct |
0 ms |
6512 KB |
Output is correct |
32 |
Correct |
0 ms |
6512 KB |
Output is correct |
33 |
Correct |
0 ms |
6512 KB |
Output is correct |
34 |
Correct |
0 ms |
6512 KB |
Output is correct |
35 |
Correct |
0 ms |
6512 KB |
Output is correct |
36 |
Correct |
0 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6512 KB |
Output is correct |
2 |
Correct |
0 ms |
6512 KB |
Output is correct |
3 |
Correct |
0 ms |
6512 KB |
Output is correct |
4 |
Correct |
0 ms |
6512 KB |
Output is correct |
5 |
Correct |
0 ms |
6512 KB |
Output is correct |
6 |
Correct |
0 ms |
6512 KB |
Output is correct |
7 |
Correct |
0 ms |
6512 KB |
Output is correct |
8 |
Correct |
0 ms |
6512 KB |
Output is correct |
9 |
Correct |
0 ms |
6512 KB |
Output is correct |
10 |
Correct |
0 ms |
6512 KB |
Output is correct |
11 |
Correct |
0 ms |
6512 KB |
Output is correct |
12 |
Correct |
0 ms |
6512 KB |
Output is correct |
13 |
Correct |
0 ms |
6512 KB |
Output is correct |
14 |
Correct |
0 ms |
6512 KB |
Output is correct |
15 |
Correct |
0 ms |
6512 KB |
Output is correct |
16 |
Correct |
0 ms |
6512 KB |
Output is correct |
17 |
Correct |
0 ms |
6512 KB |
Output is correct |
18 |
Correct |
0 ms |
6512 KB |
Output is correct |
19 |
Correct |
0 ms |
6512 KB |
Output is correct |
20 |
Correct |
0 ms |
6512 KB |
Output is correct |
21 |
Correct |
0 ms |
6512 KB |
Output is correct |
22 |
Correct |
0 ms |
6512 KB |
Output is correct |
23 |
Correct |
0 ms |
6512 KB |
Output is correct |
24 |
Correct |
0 ms |
6512 KB |
Output is correct |
25 |
Correct |
0 ms |
6512 KB |
Output is correct |
26 |
Correct |
0 ms |
6512 KB |
Output is correct |
27 |
Correct |
0 ms |
6512 KB |
Output is correct |
28 |
Correct |
0 ms |
6512 KB |
Output is correct |
29 |
Correct |
0 ms |
6512 KB |
Output is correct |
30 |
Correct |
0 ms |
6512 KB |
Output is correct |
31 |
Correct |
3 ms |
6512 KB |
Output is correct |
32 |
Correct |
3 ms |
6512 KB |
Output is correct |
33 |
Correct |
3 ms |
6512 KB |
Output is correct |
34 |
Correct |
3 ms |
6512 KB |
Output is correct |
35 |
Correct |
3 ms |
6512 KB |
Output is correct |
36 |
Correct |
3 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6512 KB |
Output is correct |
2 |
Correct |
0 ms |
6512 KB |
Output is correct |
3 |
Correct |
0 ms |
6512 KB |
Output is correct |
4 |
Correct |
0 ms |
6512 KB |
Output is correct |
5 |
Correct |
0 ms |
6512 KB |
Output is correct |
6 |
Correct |
0 ms |
6512 KB |
Output is correct |
7 |
Correct |
0 ms |
6512 KB |
Output is correct |
8 |
Correct |
0 ms |
6512 KB |
Output is correct |
9 |
Correct |
0 ms |
6512 KB |
Output is correct |
10 |
Correct |
0 ms |
6512 KB |
Output is correct |
11 |
Correct |
0 ms |
6512 KB |
Output is correct |
12 |
Correct |
0 ms |
6512 KB |
Output is correct |
13 |
Correct |
0 ms |
6512 KB |
Output is correct |
14 |
Correct |
0 ms |
6512 KB |
Output is correct |
15 |
Correct |
0 ms |
6512 KB |
Output is correct |
16 |
Correct |
0 ms |
6512 KB |
Output is correct |
17 |
Correct |
0 ms |
6512 KB |
Output is correct |
18 |
Correct |
3 ms |
6512 KB |
Output is correct |
19 |
Correct |
3 ms |
6512 KB |
Output is correct |
20 |
Correct |
3 ms |
6512 KB |
Output is correct |
21 |
Correct |
3 ms |
6512 KB |
Output is correct |
22 |
Correct |
3 ms |
6512 KB |
Output is correct |
23 |
Correct |
3 ms |
6512 KB |
Output is correct |
24 |
Correct |
3 ms |
6512 KB |
Output is correct |
25 |
Correct |
6 ms |
6512 KB |
Output is correct |
26 |
Correct |
16 ms |
6512 KB |
Output is correct |
27 |
Correct |
23 ms |
6512 KB |
Output is correct |
28 |
Correct |
33 ms |
6512 KB |
Output is correct |
29 |
Correct |
29 ms |
6512 KB |
Output is correct |
30 |
Correct |
29 ms |
6512 KB |
Output is correct |
31 |
Correct |
33 ms |
6512 KB |
Output is correct |
32 |
Correct |
29 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6512 KB |
Output is correct |
2 |
Correct |
0 ms |
6512 KB |
Output is correct |
3 |
Correct |
0 ms |
6512 KB |
Output is correct |
4 |
Correct |
0 ms |
6512 KB |
Output is correct |
5 |
Correct |
0 ms |
6512 KB |
Output is correct |
6 |
Correct |
0 ms |
6512 KB |
Output is correct |
7 |
Correct |
0 ms |
6512 KB |
Output is correct |
8 |
Correct |
0 ms |
6512 KB |
Output is correct |
9 |
Correct |
0 ms |
6512 KB |
Output is correct |
10 |
Correct |
0 ms |
6512 KB |
Output is correct |
11 |
Correct |
0 ms |
6512 KB |
Output is correct |
12 |
Correct |
0 ms |
6512 KB |
Output is correct |
13 |
Correct |
0 ms |
6512 KB |
Output is correct |
14 |
Correct |
0 ms |
6512 KB |
Output is correct |
15 |
Correct |
0 ms |
6512 KB |
Output is correct |
16 |
Correct |
0 ms |
6512 KB |
Output is correct |
17 |
Correct |
0 ms |
6512 KB |
Output is correct |
18 |
Correct |
0 ms |
6512 KB |
Output is correct |
19 |
Correct |
0 ms |
6512 KB |
Output is correct |
20 |
Correct |
0 ms |
6512 KB |
Output is correct |
21 |
Correct |
0 ms |
6512 KB |
Output is correct |
22 |
Correct |
0 ms |
6512 KB |
Output is correct |
23 |
Correct |
0 ms |
6512 KB |
Output is correct |
24 |
Correct |
0 ms |
6512 KB |
Output is correct |
25 |
Correct |
0 ms |
6512 KB |
Output is correct |
26 |
Correct |
0 ms |
6512 KB |
Output is correct |
27 |
Correct |
0 ms |
6512 KB |
Output is correct |
28 |
Correct |
0 ms |
6512 KB |
Output is correct |
29 |
Correct |
0 ms |
6512 KB |
Output is correct |
30 |
Correct |
0 ms |
6512 KB |
Output is correct |
31 |
Correct |
0 ms |
6512 KB |
Output is correct |
32 |
Correct |
0 ms |
6512 KB |
Output is correct |
33 |
Correct |
0 ms |
6512 KB |
Output is correct |
34 |
Correct |
0 ms |
6512 KB |
Output is correct |
35 |
Correct |
0 ms |
6512 KB |
Output is correct |
36 |
Correct |
0 ms |
6512 KB |
Output is correct |
37 |
Correct |
0 ms |
6512 KB |
Output is correct |
38 |
Correct |
0 ms |
6512 KB |
Output is correct |
39 |
Correct |
0 ms |
6512 KB |
Output is correct |
40 |
Correct |
0 ms |
6512 KB |
Output is correct |
41 |
Correct |
3 ms |
6512 KB |
Output is correct |
42 |
Correct |
3 ms |
6512 KB |
Output is correct |
43 |
Correct |
3 ms |
6512 KB |
Output is correct |
44 |
Correct |
3 ms |
6512 KB |
Output is correct |
45 |
Correct |
3 ms |
6512 KB |
Output is correct |
46 |
Correct |
3 ms |
6512 KB |
Output is correct |
47 |
Correct |
3 ms |
6512 KB |
Output is correct |
48 |
Correct |
9 ms |
6512 KB |
Output is correct |
49 |
Correct |
16 ms |
6512 KB |
Output is correct |
50 |
Correct |
26 ms |
6512 KB |
Output is correct |
51 |
Correct |
29 ms |
6512 KB |
Output is correct |
52 |
Correct |
36 ms |
6512 KB |
Output is correct |
53 |
Correct |
29 ms |
6512 KB |
Output is correct |
54 |
Correct |
29 ms |
6512 KB |
Output is correct |
55 |
Correct |
29 ms |
6512 KB |
Output is correct |
56 |
Correct |
3 ms |
6512 KB |
Output is correct |
57 |
Correct |
9 ms |
6512 KB |
Output is correct |
58 |
Correct |
13 ms |
6512 KB |
Output is correct |
59 |
Correct |
19 ms |
6512 KB |
Output is correct |
60 |
Correct |
26 ms |
6512 KB |
Output is correct |
61 |
Correct |
19 ms |
6512 KB |
Output is correct |
62 |
Correct |
29 ms |
6512 KB |
Output is correct |
63 |
Correct |
19 ms |
6512 KB |
Output is correct |
64 |
Correct |
23 ms |
6512 KB |
Output is correct |
65 |
Correct |
3 ms |
6512 KB |
Output is correct |
66 |
Correct |
6 ms |
6512 KB |
Output is correct |
67 |
Correct |
9 ms |
6512 KB |
Output is correct |
68 |
Correct |
13 ms |
6512 KB |
Output is correct |
69 |
Correct |
16 ms |
6512 KB |
Output is correct |
70 |
Correct |
16 ms |
6512 KB |
Output is correct |
71 |
Correct |
19 ms |
6512 KB |
Output is correct |
72 |
Correct |
19 ms |
6512 KB |
Output is correct |
73 |
Correct |
19 ms |
6512 KB |
Output is correct |
74 |
Correct |
19 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6512 KB |
Output is correct |
2 |
Correct |
0 ms |
6512 KB |
Output is correct |
3 |
Correct |
0 ms |
6512 KB |
Output is correct |
4 |
Correct |
0 ms |
6512 KB |
Output is correct |
5 |
Correct |
0 ms |
6512 KB |
Output is correct |
6 |
Correct |
0 ms |
6512 KB |
Output is correct |
7 |
Correct |
0 ms |
6512 KB |
Output is correct |
8 |
Correct |
0 ms |
6512 KB |
Output is correct |
9 |
Correct |
0 ms |
6512 KB |
Output is correct |
10 |
Correct |
0 ms |
6512 KB |
Output is correct |
11 |
Correct |
0 ms |
6512 KB |
Output is correct |
12 |
Correct |
0 ms |
6512 KB |
Output is correct |
13 |
Correct |
0 ms |
6512 KB |
Output is correct |
14 |
Correct |
0 ms |
6512 KB |
Output is correct |
15 |
Correct |
0 ms |
6512 KB |
Output is correct |
16 |
Correct |
0 ms |
6512 KB |
Output is correct |
17 |
Correct |
0 ms |
6512 KB |
Output is correct |
18 |
Correct |
0 ms |
6512 KB |
Output is correct |
19 |
Correct |
0 ms |
6512 KB |
Output is correct |
20 |
Correct |
0 ms |
6512 KB |
Output is correct |
21 |
Correct |
0 ms |
6512 KB |
Output is correct |
22 |
Correct |
0 ms |
6512 KB |
Output is correct |
23 |
Correct |
0 ms |
6512 KB |
Output is correct |
24 |
Correct |
0 ms |
6512 KB |
Output is correct |
25 |
Correct |
0 ms |
6512 KB |
Output is correct |
26 |
Correct |
0 ms |
6512 KB |
Output is correct |
27 |
Correct |
0 ms |
6512 KB |
Output is correct |
28 |
Correct |
3 ms |
6512 KB |
Output is correct |
29 |
Correct |
3 ms |
6512 KB |
Output is correct |
30 |
Correct |
3 ms |
6512 KB |
Output is correct |
31 |
Correct |
3 ms |
6512 KB |
Output is correct |
32 |
Correct |
3 ms |
6512 KB |
Output is correct |
33 |
Correct |
3 ms |
6512 KB |
Output is correct |
34 |
Correct |
3 ms |
6512 KB |
Output is correct |
35 |
Correct |
6 ms |
6512 KB |
Output is correct |
36 |
Correct |
13 ms |
6512 KB |
Output is correct |
37 |
Correct |
23 ms |
6512 KB |
Output is correct |
38 |
Correct |
39 ms |
6512 KB |
Output is correct |
39 |
Correct |
29 ms |
6512 KB |
Output is correct |
40 |
Correct |
33 ms |
6512 KB |
Output is correct |
41 |
Correct |
33 ms |
6512 KB |
Output is correct |
42 |
Correct |
33 ms |
6512 KB |
Output is correct |
43 |
Correct |
3 ms |
6512 KB |
Output is correct |
44 |
Correct |
9 ms |
6512 KB |
Output is correct |
45 |
Correct |
13 ms |
6512 KB |
Output is correct |
46 |
Correct |
23 ms |
6512 KB |
Output is correct |
47 |
Correct |
26 ms |
6512 KB |
Output is correct |
48 |
Correct |
19 ms |
6512 KB |
Output is correct |
49 |
Correct |
26 ms |
6512 KB |
Output is correct |
50 |
Correct |
19 ms |
6512 KB |
Output is correct |
51 |
Correct |
23 ms |
6512 KB |
Output is correct |
52 |
Correct |
9 ms |
6512 KB |
Output is correct |
53 |
Correct |
16 ms |
6512 KB |
Output is correct |
54 |
Correct |
26 ms |
6512 KB |
Output is correct |
55 |
Correct |
33 ms |
6512 KB |
Output is correct |
56 |
Correct |
99 ms |
6512 KB |
Output is correct |
57 |
Correct |
99 ms |
6512 KB |
Output is correct |
58 |
Correct |
89 ms |
6512 KB |
Output is correct |
59 |
Correct |
99 ms |
6512 KB |
Output is correct |
60 |
Incorrect |
183 ms |
6512 KB |
Output isn't correct |
61 |
Halted |
0 ms |
0 KB |
- |