// explained in namnamseo.tistory.com
#include <iostream>
using namespace std;
typedef long long ll;
ll data[5010], pref[5010], ans;
int n;
int A, B;
void in(){
cin>>n>>A>>B;
int i;
for(i=1; i<=n; ++i) cin>>data[i], pref[i]=pref[i-1]+data[i];
}
int dp[5010];
int min(int a,int b){ return a>b?b:a; }
bool chk_no_lb(int k){
ll mask = (~ans) & (~((1ll<<k)-1));
int i,j;
for(i=1; i<=n; ++i){
dp[i]=1e9;
for(j=0; j<i; ++j){
if(((pref[i]-pref[j])&mask) == 0){
dp[i]=min(dp[i],dp[j]+1);
}
}
}
return dp[n]<=B;
}
bool dp2[101][101];
bool chk_ks(int k){
ll mask = (~ans) & (~((1ll<<k)-1));
int i,j,t;
for(i=0;i<=100;++i) for(j=0;j<=100;++j) dp2[i][j]=0;
dp2[0][0]=1;
for(i=1; i<=n; ++i){
for(j=1; j<=B; ++j){
for(t=0; t<i; ++t){
if(dp2[t][j-1]){
if(((pref[i]-pref[t])&mask)==0){ // t is usable
dp2[i][j]=1;
}
}
}
}
}
for(i=A; i<=B; ++i){
if(dp2[n][i]) return 1;
}
return 0;
}
int main() {
in();
for(int i=40; 0<=i; --i){
if( !(A==1?chk_no_lb(i):chk_ks(i)) ) ans|=(1LL<<i);
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1828 KB |
Output is correct |
2 |
Correct |
0 ms |
1828 KB |
Output is correct |
3 |
Correct |
0 ms |
1828 KB |
Output is correct |
4 |
Correct |
0 ms |
1828 KB |
Output is correct |
5 |
Correct |
0 ms |
1828 KB |
Output is correct |
6 |
Correct |
0 ms |
1828 KB |
Output is correct |
7 |
Correct |
0 ms |
1828 KB |
Output is correct |
8 |
Correct |
0 ms |
1828 KB |
Output is correct |
9 |
Correct |
0 ms |
1828 KB |
Output is correct |
10 |
Correct |
0 ms |
1828 KB |
Output is correct |
11 |
Correct |
0 ms |
1828 KB |
Output is correct |
12 |
Correct |
0 ms |
1828 KB |
Output is correct |
13 |
Correct |
0 ms |
1828 KB |
Output is correct |
14 |
Correct |
0 ms |
1828 KB |
Output is correct |
15 |
Correct |
0 ms |
1828 KB |
Output is correct |
16 |
Correct |
0 ms |
1828 KB |
Output is correct |
17 |
Correct |
0 ms |
1828 KB |
Output is correct |
18 |
Correct |
0 ms |
1828 KB |
Output is correct |
19 |
Correct |
0 ms |
1828 KB |
Output is correct |
20 |
Correct |
0 ms |
1828 KB |
Output is correct |
21 |
Correct |
0 ms |
1828 KB |
Output is correct |
22 |
Correct |
0 ms |
1828 KB |
Output is correct |
23 |
Correct |
0 ms |
1828 KB |
Output is correct |
24 |
Correct |
0 ms |
1828 KB |
Output is correct |
25 |
Correct |
0 ms |
1828 KB |
Output is correct |
26 |
Correct |
1 ms |
1828 KB |
Output is correct |
27 |
Correct |
0 ms |
1828 KB |
Output is correct |
28 |
Correct |
0 ms |
1828 KB |
Output is correct |
29 |
Correct |
0 ms |
1828 KB |
Output is correct |
30 |
Correct |
0 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
1828 KB |
Output is correct |
32 |
Correct |
0 ms |
1828 KB |
Output is correct |
33 |
Correct |
0 ms |
1828 KB |
Output is correct |
34 |
Correct |
0 ms |
1828 KB |
Output is correct |
35 |
Correct |
0 ms |
1828 KB |
Output is correct |
36 |
Correct |
0 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1828 KB |
Output is correct |
2 |
Correct |
0 ms |
1828 KB |
Output is correct |
3 |
Correct |
0 ms |
1828 KB |
Output is correct |
4 |
Correct |
0 ms |
1828 KB |
Output is correct |
5 |
Correct |
0 ms |
1828 KB |
Output is correct |
6 |
Correct |
0 ms |
1828 KB |
Output is correct |
7 |
Correct |
0 ms |
1828 KB |
Output is correct |
8 |
Correct |
0 ms |
1828 KB |
Output is correct |
9 |
Correct |
0 ms |
1828 KB |
Output is correct |
10 |
Correct |
0 ms |
1828 KB |
Output is correct |
11 |
Correct |
0 ms |
1828 KB |
Output is correct |
12 |
Correct |
0 ms |
1828 KB |
Output is correct |
13 |
Correct |
0 ms |
1828 KB |
Output is correct |
14 |
Correct |
0 ms |
1828 KB |
Output is correct |
15 |
Correct |
0 ms |
1828 KB |
Output is correct |
16 |
Correct |
0 ms |
1828 KB |
Output is correct |
17 |
Correct |
0 ms |
1828 KB |
Output is correct |
18 |
Correct |
0 ms |
1828 KB |
Output is correct |
19 |
Correct |
0 ms |
1828 KB |
Output is correct |
20 |
Correct |
1 ms |
1828 KB |
Output is correct |
21 |
Correct |
0 ms |
1828 KB |
Output is correct |
22 |
Correct |
0 ms |
1828 KB |
Output is correct |
23 |
Correct |
0 ms |
1828 KB |
Output is correct |
24 |
Correct |
0 ms |
1828 KB |
Output is correct |
25 |
Correct |
0 ms |
1828 KB |
Output is correct |
26 |
Correct |
1 ms |
1828 KB |
Output is correct |
27 |
Correct |
0 ms |
1828 KB |
Output is correct |
28 |
Correct |
0 ms |
1828 KB |
Output is correct |
29 |
Correct |
0 ms |
1828 KB |
Output is correct |
30 |
Correct |
0 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
1828 KB |
Output is correct |
32 |
Correct |
0 ms |
1828 KB |
Output is correct |
33 |
Correct |
0 ms |
1828 KB |
Output is correct |
34 |
Correct |
0 ms |
1828 KB |
Output is correct |
35 |
Correct |
0 ms |
1828 KB |
Output is correct |
36 |
Correct |
0 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1828 KB |
Output is correct |
2 |
Correct |
0 ms |
1828 KB |
Output is correct |
3 |
Correct |
0 ms |
1828 KB |
Output is correct |
4 |
Correct |
0 ms |
1828 KB |
Output is correct |
5 |
Correct |
0 ms |
1828 KB |
Output is correct |
6 |
Correct |
0 ms |
1828 KB |
Output is correct |
7 |
Correct |
0 ms |
1828 KB |
Output is correct |
8 |
Correct |
0 ms |
1828 KB |
Output is correct |
9 |
Correct |
0 ms |
1828 KB |
Output is correct |
10 |
Correct |
0 ms |
1828 KB |
Output is correct |
11 |
Correct |
0 ms |
1828 KB |
Output is correct |
12 |
Correct |
0 ms |
1828 KB |
Output is correct |
13 |
Correct |
0 ms |
1828 KB |
Output is correct |
14 |
Correct |
0 ms |
1828 KB |
Output is correct |
15 |
Correct |
0 ms |
1828 KB |
Output is correct |
16 |
Correct |
0 ms |
1828 KB |
Output is correct |
17 |
Correct |
0 ms |
1828 KB |
Output is correct |
18 |
Correct |
0 ms |
1828 KB |
Output is correct |
19 |
Correct |
0 ms |
1828 KB |
Output is correct |
20 |
Correct |
0 ms |
1828 KB |
Output is correct |
21 |
Correct |
0 ms |
1828 KB |
Output is correct |
22 |
Correct |
0 ms |
1828 KB |
Output is correct |
23 |
Correct |
0 ms |
1828 KB |
Output is correct |
24 |
Correct |
0 ms |
1828 KB |
Output is correct |
25 |
Correct |
0 ms |
1828 KB |
Output is correct |
26 |
Correct |
0 ms |
1828 KB |
Output is correct |
27 |
Correct |
0 ms |
1828 KB |
Output is correct |
28 |
Correct |
0 ms |
1828 KB |
Output is correct |
29 |
Correct |
0 ms |
1828 KB |
Output is correct |
30 |
Correct |
0 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
1828 KB |
Output is correct |
32 |
Correct |
0 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1828 KB |
Output is correct |
2 |
Correct |
0 ms |
1828 KB |
Output is correct |
3 |
Correct |
0 ms |
1828 KB |
Output is correct |
4 |
Correct |
0 ms |
1828 KB |
Output is correct |
5 |
Correct |
0 ms |
1828 KB |
Output is correct |
6 |
Correct |
0 ms |
1828 KB |
Output is correct |
7 |
Correct |
0 ms |
1828 KB |
Output is correct |
8 |
Correct |
0 ms |
1828 KB |
Output is correct |
9 |
Correct |
0 ms |
1828 KB |
Output is correct |
10 |
Correct |
0 ms |
1828 KB |
Output is correct |
11 |
Correct |
0 ms |
1828 KB |
Output is correct |
12 |
Correct |
0 ms |
1828 KB |
Output is correct |
13 |
Correct |
0 ms |
1828 KB |
Output is correct |
14 |
Correct |
0 ms |
1828 KB |
Output is correct |
15 |
Correct |
0 ms |
1828 KB |
Output is correct |
16 |
Correct |
0 ms |
1828 KB |
Output is correct |
17 |
Correct |
0 ms |
1828 KB |
Output is correct |
18 |
Correct |
0 ms |
1828 KB |
Output is correct |
19 |
Correct |
0 ms |
1828 KB |
Output is correct |
20 |
Correct |
0 ms |
1828 KB |
Output is correct |
21 |
Correct |
0 ms |
1828 KB |
Output is correct |
22 |
Correct |
0 ms |
1828 KB |
Output is correct |
23 |
Correct |
0 ms |
1828 KB |
Output is correct |
24 |
Correct |
1 ms |
1828 KB |
Output is correct |
25 |
Correct |
0 ms |
1828 KB |
Output is correct |
26 |
Correct |
0 ms |
1828 KB |
Output is correct |
27 |
Correct |
0 ms |
1828 KB |
Output is correct |
28 |
Correct |
0 ms |
1828 KB |
Output is correct |
29 |
Correct |
0 ms |
1828 KB |
Output is correct |
30 |
Correct |
0 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
1828 KB |
Output is correct |
32 |
Correct |
0 ms |
1828 KB |
Output is correct |
33 |
Correct |
0 ms |
1828 KB |
Output is correct |
34 |
Correct |
0 ms |
1828 KB |
Output is correct |
35 |
Correct |
0 ms |
1828 KB |
Output is correct |
36 |
Correct |
0 ms |
1828 KB |
Output is correct |
37 |
Correct |
0 ms |
1828 KB |
Output is correct |
38 |
Correct |
0 ms |
1828 KB |
Output is correct |
39 |
Correct |
0 ms |
1828 KB |
Output is correct |
40 |
Correct |
0 ms |
1828 KB |
Output is correct |
41 |
Correct |
0 ms |
1828 KB |
Output is correct |
42 |
Correct |
0 ms |
1828 KB |
Output is correct |
43 |
Correct |
0 ms |
1828 KB |
Output is correct |
44 |
Correct |
0 ms |
1828 KB |
Output is correct |
45 |
Correct |
0 ms |
1828 KB |
Output is correct |
46 |
Correct |
0 ms |
1828 KB |
Output is correct |
47 |
Correct |
0 ms |
1828 KB |
Output is correct |
48 |
Correct |
0 ms |
1828 KB |
Output is correct |
49 |
Correct |
0 ms |
1828 KB |
Output is correct |
50 |
Correct |
0 ms |
1828 KB |
Output is correct |
51 |
Correct |
0 ms |
1828 KB |
Output is correct |
52 |
Correct |
0 ms |
1828 KB |
Output is correct |
53 |
Correct |
0 ms |
1828 KB |
Output is correct |
54 |
Correct |
0 ms |
1828 KB |
Output is correct |
55 |
Correct |
0 ms |
1828 KB |
Output is correct |
56 |
Correct |
0 ms |
1828 KB |
Output is correct |
57 |
Correct |
0 ms |
1828 KB |
Output is correct |
58 |
Correct |
0 ms |
1828 KB |
Output is correct |
59 |
Correct |
0 ms |
1828 KB |
Output is correct |
60 |
Correct |
0 ms |
1828 KB |
Output is correct |
61 |
Correct |
1 ms |
1828 KB |
Output is correct |
62 |
Correct |
0 ms |
1828 KB |
Output is correct |
63 |
Correct |
0 ms |
1828 KB |
Output is correct |
64 |
Correct |
25 ms |
1828 KB |
Output is correct |
65 |
Correct |
0 ms |
1828 KB |
Output is correct |
66 |
Correct |
0 ms |
1828 KB |
Output is correct |
67 |
Correct |
6 ms |
1828 KB |
Output is correct |
68 |
Correct |
16 ms |
1828 KB |
Output is correct |
69 |
Correct |
31 ms |
1828 KB |
Output is correct |
70 |
Correct |
32 ms |
1828 KB |
Output is correct |
71 |
Correct |
1 ms |
1828 KB |
Output is correct |
72 |
Correct |
32 ms |
1828 KB |
Output is correct |
73 |
Correct |
25 ms |
1828 KB |
Output is correct |
74 |
Correct |
23 ms |
1828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1828 KB |
Output is correct |
2 |
Correct |
0 ms |
1828 KB |
Output is correct |
3 |
Correct |
0 ms |
1828 KB |
Output is correct |
4 |
Correct |
0 ms |
1828 KB |
Output is correct |
5 |
Correct |
0 ms |
1828 KB |
Output is correct |
6 |
Correct |
0 ms |
1828 KB |
Output is correct |
7 |
Correct |
0 ms |
1828 KB |
Output is correct |
8 |
Correct |
0 ms |
1828 KB |
Output is correct |
9 |
Correct |
0 ms |
1828 KB |
Output is correct |
10 |
Correct |
0 ms |
1828 KB |
Output is correct |
11 |
Correct |
0 ms |
1828 KB |
Output is correct |
12 |
Correct |
0 ms |
1828 KB |
Output is correct |
13 |
Correct |
0 ms |
1828 KB |
Output is correct |
14 |
Correct |
0 ms |
1828 KB |
Output is correct |
15 |
Correct |
0 ms |
1828 KB |
Output is correct |
16 |
Correct |
0 ms |
1828 KB |
Output is correct |
17 |
Correct |
0 ms |
1828 KB |
Output is correct |
18 |
Correct |
0 ms |
1828 KB |
Output is correct |
19 |
Correct |
0 ms |
1828 KB |
Output is correct |
20 |
Correct |
0 ms |
1828 KB |
Output is correct |
21 |
Correct |
0 ms |
1828 KB |
Output is correct |
22 |
Correct |
0 ms |
1828 KB |
Output is correct |
23 |
Correct |
0 ms |
1828 KB |
Output is correct |
24 |
Correct |
0 ms |
1828 KB |
Output is correct |
25 |
Correct |
0 ms |
1828 KB |
Output is correct |
26 |
Correct |
0 ms |
1828 KB |
Output is correct |
27 |
Correct |
0 ms |
1828 KB |
Output is correct |
28 |
Correct |
0 ms |
1828 KB |
Output is correct |
29 |
Correct |
0 ms |
1828 KB |
Output is correct |
30 |
Correct |
0 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
1828 KB |
Output is correct |
32 |
Correct |
0 ms |
1828 KB |
Output is correct |
33 |
Correct |
0 ms |
1828 KB |
Output is correct |
34 |
Correct |
0 ms |
1828 KB |
Output is correct |
35 |
Correct |
0 ms |
1828 KB |
Output is correct |
36 |
Correct |
0 ms |
1828 KB |
Output is correct |
37 |
Correct |
1 ms |
1828 KB |
Output is correct |
38 |
Correct |
0 ms |
1828 KB |
Output is correct |
39 |
Correct |
0 ms |
1828 KB |
Output is correct |
40 |
Correct |
0 ms |
1828 KB |
Output is correct |
41 |
Correct |
0 ms |
1828 KB |
Output is correct |
42 |
Correct |
1 ms |
1828 KB |
Output is correct |
43 |
Correct |
0 ms |
1828 KB |
Output is correct |
44 |
Correct |
0 ms |
1828 KB |
Output is correct |
45 |
Correct |
0 ms |
1828 KB |
Output is correct |
46 |
Correct |
0 ms |
1828 KB |
Output is correct |
47 |
Correct |
0 ms |
1828 KB |
Output is correct |
48 |
Correct |
0 ms |
1828 KB |
Output is correct |
49 |
Correct |
0 ms |
1828 KB |
Output is correct |
50 |
Correct |
0 ms |
1828 KB |
Output is correct |
51 |
Correct |
0 ms |
1828 KB |
Output is correct |
52 |
Correct |
10 ms |
1828 KB |
Output is correct |
53 |
Correct |
15 ms |
1828 KB |
Output is correct |
54 |
Correct |
30 ms |
1828 KB |
Output is correct |
55 |
Correct |
27 ms |
1828 KB |
Output is correct |
56 |
Correct |
96 ms |
1828 KB |
Output is correct |
57 |
Correct |
95 ms |
1828 KB |
Output is correct |
58 |
Correct |
90 ms |
1828 KB |
Output is correct |
59 |
Correct |
90 ms |
1828 KB |
Output is correct |
60 |
Correct |
103 ms |
1828 KB |
Output is correct |
61 |
Correct |
0 ms |
1828 KB |
Output is correct |
62 |
Correct |
15 ms |
1828 KB |
Output is correct |
63 |
Correct |
30 ms |
1828 KB |
Output is correct |
64 |
Correct |
26 ms |
1828 KB |
Output is correct |
65 |
Correct |
48 ms |
1828 KB |
Output is correct |
66 |
Correct |
72 ms |
1828 KB |
Output is correct |
67 |
Correct |
96 ms |
1828 KB |
Output is correct |
68 |
Correct |
96 ms |
1828 KB |
Output is correct |
69 |
Correct |
92 ms |
1828 KB |
Output is correct |