#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = (int)1e2+10;
const ll LINF = (ll)1e18;
int n, A, B;
ll a[maxn], pre[maxn]; ll ans=LINF;
bool dp[maxn/2][maxn/2][25][1028];
void recur(int pos, int lpos, int knum, int Or){
if(dp[pos][lpos][knum][Or]) return;
dp[pos][lpos][knum][Or]=1;
if(pos==n+1) return;
if(pos!=n) recur(pos+1, lpos, knum, Or);
recur(pos+1, pos, knum+1, Or|(pre[pos]-pre[lpos]));
}
int32_t main() {
cin >> n >> A >> B;
for(int i = 0; i < n; i++) cin >> a[i], pre[i+1]=pre[i]+a[i];
if(n<=20){
for(int mask = 0; mask < (1<<n); mask++){
int num = __builtin_popcount(mask);
if(num<A or num>B or !(mask&(1<<(n-1)))) continue;
ll Or = 0, sum = 0;
for(int i = 0; i < n; i++){
if(mask&(1<<i)) sum+=a[i], Or|=sum, sum=0;
else sum+=a[i];
}
ans = min(ans, Or);
}
}
else if(n<=50){
recur(1,0,1,0);
for(int i = A+1; i <= B+1; i++)
for(int k = 0; k < 1028; k++)
if(dp[n+1][n][B+1][k]) ans = min(ans, (ll)k);
}
else if(n<=100 and A==1){
const int mxOR = 2050;
int dp[110][mxOR];
for(int i = 0; i <= n; i++)
for(int j = 0; j < mxOR; j++)
dp[i][j]=n+1;
dp[0][0]=0; ll sum;
for(int i = 0; i < n; i++)
for(int j = 0; j < mxOR; j++)
for(int k = i+1; k <= n; k++)
sum=pre[k]-pre[i], dp[k][j|sum]=min(dp[k][j|sum], dp[i][j]+1);
for(int j = 0; j < mxOR; j++)
if(dp[n][j]<=B) ans=min(ans,(ll)j);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
29 ms |
1188 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
5 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1188 KB |
Output is correct |
23 |
Correct |
6 ms |
1180 KB |
Output is correct |
24 |
Correct |
3 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Correct |
29 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
2 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1108 KB |
Output is correct |
32 |
Correct |
4 ms |
1108 KB |
Output is correct |
33 |
Correct |
27 ms |
1108 KB |
Output is correct |
34 |
Correct |
29 ms |
1108 KB |
Output is correct |
35 |
Correct |
3 ms |
1192 KB |
Output is correct |
36 |
Correct |
30 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
4 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
1108 KB |
Output is correct |
11 |
Correct |
4 ms |
1108 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
30 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1188 KB |
Output is correct |
23 |
Correct |
6 ms |
1108 KB |
Output is correct |
24 |
Correct |
4 ms |
1108 KB |
Output is correct |
25 |
Correct |
6 ms |
1188 KB |
Output is correct |
26 |
Correct |
31 ms |
1108 KB |
Output is correct |
27 |
Correct |
2 ms |
3540 KB |
Output is correct |
28 |
Correct |
4 ms |
4820 KB |
Output is correct |
29 |
Correct |
8 ms |
12116 KB |
Output is correct |
30 |
Correct |
10 ms |
15208 KB |
Output is correct |
31 |
Correct |
17 ms |
22712 KB |
Output is correct |
32 |
Correct |
17 ms |
22700 KB |
Output is correct |
33 |
Correct |
16 ms |
22676 KB |
Output is correct |
34 |
Correct |
16 ms |
22768 KB |
Output is correct |
35 |
Correct |
16 ms |
22740 KB |
Output is correct |
36 |
Correct |
17 ms |
22740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1184 KB |
Output is correct |
10 |
Correct |
4 ms |
1188 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
30 ms |
1108 KB |
Output is correct |
14 |
Correct |
2 ms |
3540 KB |
Output is correct |
15 |
Correct |
3 ms |
4820 KB |
Output is correct |
16 |
Correct |
8 ms |
12116 KB |
Output is correct |
17 |
Correct |
10 ms |
15316 KB |
Output is correct |
18 |
Correct |
17 ms |
22756 KB |
Output is correct |
19 |
Correct |
16 ms |
22680 KB |
Output is correct |
20 |
Correct |
18 ms |
22728 KB |
Output is correct |
21 |
Correct |
16 ms |
22784 KB |
Output is correct |
22 |
Correct |
16 ms |
22788 KB |
Output is correct |
23 |
Correct |
19 ms |
22784 KB |
Output is correct |
24 |
Correct |
11 ms |
1184 KB |
Output is correct |
25 |
Correct |
19 ms |
1176 KB |
Output is correct |
26 |
Correct |
24 ms |
1108 KB |
Output is correct |
27 |
Correct |
33 ms |
1108 KB |
Output is correct |
28 |
Correct |
40 ms |
1108 KB |
Output is correct |
29 |
Correct |
40 ms |
1108 KB |
Output is correct |
30 |
Correct |
40 ms |
1108 KB |
Output is correct |
31 |
Correct |
37 ms |
1108 KB |
Output is correct |
32 |
Correct |
39 ms |
1188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
1188 KB |
Output is correct |
12 |
Correct |
4 ms |
1112 KB |
Output is correct |
13 |
Correct |
29 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
6 ms |
1108 KB |
Output is correct |
22 |
Correct |
6 ms |
1108 KB |
Output is correct |
23 |
Correct |
6 ms |
1108 KB |
Output is correct |
24 |
Correct |
3 ms |
1108 KB |
Output is correct |
25 |
Correct |
7 ms |
1184 KB |
Output is correct |
26 |
Correct |
28 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
2 ms |
1108 KB |
Output is correct |
31 |
Correct |
6 ms |
1184 KB |
Output is correct |
32 |
Correct |
3 ms |
1108 KB |
Output is correct |
33 |
Correct |
28 ms |
1168 KB |
Output is correct |
34 |
Correct |
29 ms |
1172 KB |
Output is correct |
35 |
Correct |
3 ms |
1108 KB |
Output is correct |
36 |
Correct |
31 ms |
1108 KB |
Output is correct |
37 |
Correct |
2 ms |
3540 KB |
Output is correct |
38 |
Correct |
3 ms |
4820 KB |
Output is correct |
39 |
Correct |
8 ms |
12076 KB |
Output is correct |
40 |
Correct |
10 ms |
15268 KB |
Output is correct |
41 |
Correct |
19 ms |
22736 KB |
Output is correct |
42 |
Correct |
16 ms |
22740 KB |
Output is correct |
43 |
Correct |
15 ms |
22664 KB |
Output is correct |
44 |
Correct |
16 ms |
22772 KB |
Output is correct |
45 |
Correct |
18 ms |
22760 KB |
Output is correct |
46 |
Correct |
17 ms |
22752 KB |
Output is correct |
47 |
Correct |
11 ms |
1188 KB |
Output is correct |
48 |
Correct |
17 ms |
1188 KB |
Output is correct |
49 |
Correct |
25 ms |
1180 KB |
Output is correct |
50 |
Correct |
33 ms |
1108 KB |
Output is correct |
51 |
Correct |
39 ms |
1168 KB |
Output is correct |
52 |
Correct |
39 ms |
1108 KB |
Output is correct |
53 |
Correct |
40 ms |
1108 KB |
Output is correct |
54 |
Correct |
40 ms |
1108 KB |
Output is correct |
55 |
Correct |
39 ms |
1108 KB |
Output is correct |
56 |
Runtime error |
3 ms |
2132 KB |
Execution killed with signal 11 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
3 ms |
1108 KB |
Output is correct |
9 |
Correct |
3 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
4 ms |
1108 KB |
Output is correct |
13 |
Correct |
29 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
2 ms |
1108 KB |
Output is correct |
18 |
Correct |
6 ms |
1188 KB |
Output is correct |
19 |
Correct |
3 ms |
1192 KB |
Output is correct |
20 |
Correct |
27 ms |
1108 KB |
Output is correct |
21 |
Correct |
29 ms |
1164 KB |
Output is correct |
22 |
Correct |
4 ms |
1108 KB |
Output is correct |
23 |
Correct |
29 ms |
1108 KB |
Output is correct |
24 |
Correct |
2 ms |
3540 KB |
Output is correct |
25 |
Correct |
3 ms |
4820 KB |
Output is correct |
26 |
Correct |
8 ms |
12116 KB |
Output is correct |
27 |
Correct |
11 ms |
15332 KB |
Output is correct |
28 |
Correct |
19 ms |
22756 KB |
Output is correct |
29 |
Correct |
17 ms |
22724 KB |
Output is correct |
30 |
Correct |
17 ms |
22708 KB |
Output is correct |
31 |
Correct |
17 ms |
22740 KB |
Output is correct |
32 |
Correct |
15 ms |
22740 KB |
Output is correct |
33 |
Correct |
17 ms |
22740 KB |
Output is correct |
34 |
Correct |
11 ms |
1108 KB |
Output is correct |
35 |
Correct |
18 ms |
1108 KB |
Output is correct |
36 |
Correct |
25 ms |
1196 KB |
Output is correct |
37 |
Correct |
34 ms |
1164 KB |
Output is correct |
38 |
Correct |
41 ms |
1164 KB |
Output is correct |
39 |
Correct |
41 ms |
1108 KB |
Output is correct |
40 |
Correct |
40 ms |
1108 KB |
Output is correct |
41 |
Correct |
41 ms |
1168 KB |
Output is correct |
42 |
Correct |
41 ms |
1180 KB |
Output is correct |
43 |
Runtime error |
3 ms |
2152 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |