#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=2001;
const int mod=998244353;
const int mxlogN=40;
const int mxK=26;
const int inf=1e9;
const int K=600;
int dp[mxN][mxN], a[mxN], n, A, B;
int vis[mxN];
ll check(int i, int k, ll msk, bool b)
{
if(!b)
{
if(i==n) return k>=A&&k<=B;
if(~dp[i][k]) return dp[i][k];
ll sum=0;
for(int j=i+1; j<=n; j++)
{
sum+=a[j-1];
if((msk&sum)==sum) if(check(j,k+1,msk,0)) return dp[i][k]=1;
}
return dp[i][k]=0;
}
else
{
queue<int> q; q.push(0);
for(int i=0; i<=n; i++) vis[i]=0;
while(q.size())
{
int i=q.front(); q.pop();
ll sum=0;
for(int j=i+1; j<=n; j++)
{
sum+=a[j-1];
if((msk&sum)==sum)
{
if(!vis[j])
{
vis[j]=vis[i]+1;
q.push(j);
}
}
}
}
return vis[n]&&vis[n]<=B;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
cin >> n >> A >> B;
for(int i=0; i<n; i++) cin >> a[i];
ll msk=(1LL<<(mxlogN+1))-1;
for(int j=0; j<=mxlogN; j++)
{
msk^=check(0,0,msk^1LL<<(mxlogN-j),n>100)<<(mxlogN-j);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
}
cout << msk << "\n";
}
/*
6 2 2
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
15980 KB |
Output is correct |
2 |
Correct |
72 ms |
15988 KB |
Output is correct |
3 |
Correct |
83 ms |
15984 KB |
Output is correct |
4 |
Correct |
78 ms |
15988 KB |
Output is correct |
5 |
Correct |
72 ms |
15956 KB |
Output is correct |
6 |
Correct |
73 ms |
15956 KB |
Output is correct |
7 |
Correct |
75 ms |
15956 KB |
Output is correct |
8 |
Correct |
75 ms |
15984 KB |
Output is correct |
9 |
Correct |
85 ms |
15956 KB |
Output is correct |
10 |
Correct |
77 ms |
15988 KB |
Output is correct |
11 |
Correct |
71 ms |
15996 KB |
Output is correct |
12 |
Correct |
76 ms |
15988 KB |
Output is correct |
13 |
Correct |
80 ms |
16076 KB |
Output is correct |
14 |
Correct |
80 ms |
15956 KB |
Output is correct |
15 |
Correct |
79 ms |
15932 KB |
Output is correct |
16 |
Correct |
72 ms |
15984 KB |
Output is correct |
17 |
Correct |
74 ms |
16012 KB |
Output is correct |
18 |
Correct |
73 ms |
15984 KB |
Output is correct |
19 |
Correct |
78 ms |
16048 KB |
Output is correct |
20 |
Correct |
74 ms |
15872 KB |
Output is correct |
21 |
Correct |
75 ms |
15988 KB |
Output is correct |
22 |
Correct |
73 ms |
15956 KB |
Output is correct |
23 |
Correct |
76 ms |
15980 KB |
Output is correct |
24 |
Correct |
78 ms |
15984 KB |
Output is correct |
25 |
Correct |
80 ms |
15956 KB |
Output is correct |
26 |
Correct |
73 ms |
15984 KB |
Output is correct |
27 |
Correct |
74 ms |
15988 KB |
Output is correct |
28 |
Correct |
75 ms |
15956 KB |
Output is correct |
29 |
Correct |
73 ms |
15956 KB |
Output is correct |
30 |
Correct |
73 ms |
15984 KB |
Output is correct |
31 |
Correct |
81 ms |
15956 KB |
Output is correct |
32 |
Correct |
78 ms |
15992 KB |
Output is correct |
33 |
Correct |
72 ms |
15956 KB |
Output is correct |
34 |
Correct |
78 ms |
15984 KB |
Output is correct |
35 |
Correct |
80 ms |
15992 KB |
Output is correct |
36 |
Correct |
81 ms |
16004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
15988 KB |
Output is correct |
2 |
Correct |
73 ms |
15984 KB |
Output is correct |
3 |
Correct |
73 ms |
15956 KB |
Output is correct |
4 |
Correct |
75 ms |
15984 KB |
Output is correct |
5 |
Correct |
73 ms |
15980 KB |
Output is correct |
6 |
Correct |
73 ms |
15984 KB |
Output is correct |
7 |
Correct |
74 ms |
15980 KB |
Output is correct |
8 |
Correct |
73 ms |
15956 KB |
Output is correct |
9 |
Correct |
71 ms |
15956 KB |
Output is correct |
10 |
Correct |
73 ms |
15956 KB |
Output is correct |
11 |
Correct |
73 ms |
15984 KB |
Output is correct |
12 |
Correct |
75 ms |
15956 KB |
Output is correct |
13 |
Correct |
74 ms |
15980 KB |
Output is correct |
14 |
Correct |
73 ms |
15964 KB |
Output is correct |
15 |
Correct |
78 ms |
15988 KB |
Output is correct |
16 |
Correct |
72 ms |
15956 KB |
Output is correct |
17 |
Correct |
83 ms |
15984 KB |
Output is correct |
18 |
Correct |
75 ms |
15980 KB |
Output is correct |
19 |
Correct |
74 ms |
15996 KB |
Output is correct |
20 |
Correct |
73 ms |
15956 KB |
Output is correct |
21 |
Correct |
81 ms |
15956 KB |
Output is correct |
22 |
Correct |
77 ms |
15920 KB |
Output is correct |
23 |
Correct |
82 ms |
16076 KB |
Output is correct |
24 |
Correct |
73 ms |
15956 KB |
Output is correct |
25 |
Correct |
76 ms |
15984 KB |
Output is correct |
26 |
Correct |
83 ms |
15984 KB |
Output is correct |
27 |
Correct |
81 ms |
15956 KB |
Output is correct |
28 |
Correct |
74 ms |
15984 KB |
Output is correct |
29 |
Correct |
74 ms |
15988 KB |
Output is correct |
30 |
Correct |
77 ms |
15988 KB |
Output is correct |
31 |
Correct |
74 ms |
15984 KB |
Output is correct |
32 |
Correct |
81 ms |
15956 KB |
Output is correct |
33 |
Correct |
92 ms |
15952 KB |
Output is correct |
34 |
Correct |
74 ms |
15956 KB |
Output is correct |
35 |
Correct |
76 ms |
15956 KB |
Output is correct |
36 |
Correct |
79 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
15956 KB |
Output is correct |
2 |
Correct |
75 ms |
15980 KB |
Output is correct |
3 |
Correct |
74 ms |
15984 KB |
Output is correct |
4 |
Correct |
75 ms |
15984 KB |
Output is correct |
5 |
Correct |
74 ms |
15956 KB |
Output is correct |
6 |
Correct |
73 ms |
15984 KB |
Output is correct |
7 |
Correct |
73 ms |
15956 KB |
Output is correct |
8 |
Correct |
75 ms |
15980 KB |
Output is correct |
9 |
Correct |
72 ms |
15980 KB |
Output is correct |
10 |
Correct |
75 ms |
15988 KB |
Output is correct |
11 |
Correct |
77 ms |
15956 KB |
Output is correct |
12 |
Correct |
71 ms |
15888 KB |
Output is correct |
13 |
Correct |
73 ms |
15980 KB |
Output is correct |
14 |
Correct |
73 ms |
15956 KB |
Output is correct |
15 |
Correct |
73 ms |
15980 KB |
Output is correct |
16 |
Correct |
88 ms |
15956 KB |
Output is correct |
17 |
Correct |
76 ms |
15988 KB |
Output is correct |
18 |
Correct |
80 ms |
16004 KB |
Output is correct |
19 |
Correct |
73 ms |
15956 KB |
Output is correct |
20 |
Correct |
75 ms |
15952 KB |
Output is correct |
21 |
Correct |
78 ms |
15984 KB |
Output is correct |
22 |
Correct |
81 ms |
15988 KB |
Output is correct |
23 |
Correct |
87 ms |
15992 KB |
Output is correct |
24 |
Correct |
79 ms |
15988 KB |
Output is correct |
25 |
Correct |
80 ms |
15992 KB |
Output is correct |
26 |
Correct |
89 ms |
16008 KB |
Output is correct |
27 |
Correct |
74 ms |
16004 KB |
Output is correct |
28 |
Correct |
73 ms |
16000 KB |
Output is correct |
29 |
Correct |
73 ms |
15996 KB |
Output is correct |
30 |
Correct |
112 ms |
16076 KB |
Output is correct |
31 |
Correct |
80 ms |
15996 KB |
Output is correct |
32 |
Correct |
76 ms |
15956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
15956 KB |
Output is correct |
2 |
Correct |
75 ms |
15984 KB |
Output is correct |
3 |
Correct |
74 ms |
15988 KB |
Output is correct |
4 |
Correct |
73 ms |
15956 KB |
Output is correct |
5 |
Correct |
79 ms |
15988 KB |
Output is correct |
6 |
Correct |
82 ms |
15988 KB |
Output is correct |
7 |
Correct |
80 ms |
15956 KB |
Output is correct |
8 |
Correct |
79 ms |
15956 KB |
Output is correct |
9 |
Correct |
81 ms |
15956 KB |
Output is correct |
10 |
Correct |
75 ms |
15956 KB |
Output is correct |
11 |
Correct |
73 ms |
15956 KB |
Output is correct |
12 |
Correct |
72 ms |
15892 KB |
Output is correct |
13 |
Correct |
74 ms |
15956 KB |
Output is correct |
14 |
Correct |
84 ms |
15980 KB |
Output is correct |
15 |
Correct |
83 ms |
15956 KB |
Output is correct |
16 |
Correct |
77 ms |
15884 KB |
Output is correct |
17 |
Correct |
76 ms |
15984 KB |
Output is correct |
18 |
Correct |
81 ms |
15956 KB |
Output is correct |
19 |
Correct |
80 ms |
15980 KB |
Output is correct |
20 |
Correct |
77 ms |
15992 KB |
Output is correct |
21 |
Correct |
81 ms |
15892 KB |
Output is correct |
22 |
Correct |
75 ms |
15980 KB |
Output is correct |
23 |
Correct |
78 ms |
15956 KB |
Output is correct |
24 |
Correct |
78 ms |
15880 KB |
Output is correct |
25 |
Correct |
78 ms |
15980 KB |
Output is correct |
26 |
Correct |
79 ms |
15916 KB |
Output is correct |
27 |
Correct |
81 ms |
15956 KB |
Output is correct |
28 |
Correct |
74 ms |
15956 KB |
Output is correct |
29 |
Correct |
74 ms |
15984 KB |
Output is correct |
30 |
Correct |
83 ms |
15988 KB |
Output is correct |
31 |
Correct |
75 ms |
15956 KB |
Output is correct |
32 |
Correct |
73 ms |
15920 KB |
Output is correct |
33 |
Correct |
75 ms |
15956 KB |
Output is correct |
34 |
Correct |
75 ms |
15992 KB |
Output is correct |
35 |
Correct |
75 ms |
16076 KB |
Output is correct |
36 |
Correct |
80 ms |
15956 KB |
Output is correct |
37 |
Correct |
78 ms |
15916 KB |
Output is correct |
38 |
Correct |
74 ms |
15984 KB |
Output is correct |
39 |
Correct |
80 ms |
15984 KB |
Output is correct |
40 |
Correct |
74 ms |
15988 KB |
Output is correct |
41 |
Correct |
77 ms |
15984 KB |
Output is correct |
42 |
Correct |
81 ms |
15988 KB |
Output is correct |
43 |
Correct |
81 ms |
15988 KB |
Output is correct |
44 |
Correct |
76 ms |
15992 KB |
Output is correct |
45 |
Correct |
79 ms |
15988 KB |
Output is correct |
46 |
Correct |
80 ms |
15988 KB |
Output is correct |
47 |
Correct |
88 ms |
15988 KB |
Output is correct |
48 |
Correct |
85 ms |
15952 KB |
Output is correct |
49 |
Correct |
79 ms |
15996 KB |
Output is correct |
50 |
Correct |
77 ms |
16000 KB |
Output is correct |
51 |
Correct |
74 ms |
16000 KB |
Output is correct |
52 |
Correct |
83 ms |
15956 KB |
Output is correct |
53 |
Correct |
103 ms |
15992 KB |
Output is correct |
54 |
Correct |
77 ms |
15956 KB |
Output is correct |
55 |
Correct |
77 ms |
16016 KB |
Output is correct |
56 |
Correct |
74 ms |
15956 KB |
Output is correct |
57 |
Correct |
77 ms |
15992 KB |
Output is correct |
58 |
Correct |
86 ms |
16000 KB |
Output is correct |
59 |
Correct |
77 ms |
15996 KB |
Output is correct |
60 |
Correct |
74 ms |
16000 KB |
Output is correct |
61 |
Correct |
82 ms |
15992 KB |
Output is correct |
62 |
Correct |
76 ms |
15956 KB |
Output is correct |
63 |
Correct |
75 ms |
16004 KB |
Output is correct |
64 |
Correct |
85 ms |
15992 KB |
Output is correct |
65 |
Correct |
82 ms |
15928 KB |
Output is correct |
66 |
Correct |
78 ms |
15956 KB |
Output is correct |
67 |
Correct |
84 ms |
15956 KB |
Output is correct |
68 |
Correct |
80 ms |
16000 KB |
Output is correct |
69 |
Correct |
80 ms |
15956 KB |
Output is correct |
70 |
Correct |
79 ms |
16000 KB |
Output is correct |
71 |
Correct |
87 ms |
16000 KB |
Output is correct |
72 |
Correct |
74 ms |
15956 KB |
Output is correct |
73 |
Correct |
87 ms |
15956 KB |
Output is correct |
74 |
Correct |
75 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
15980 KB |
Output is correct |
2 |
Correct |
76 ms |
15976 KB |
Output is correct |
3 |
Correct |
85 ms |
15984 KB |
Output is correct |
4 |
Correct |
82 ms |
15984 KB |
Output is correct |
5 |
Correct |
77 ms |
15984 KB |
Output is correct |
6 |
Correct |
72 ms |
15980 KB |
Output is correct |
7 |
Correct |
72 ms |
15956 KB |
Output is correct |
8 |
Correct |
84 ms |
15984 KB |
Output is correct |
9 |
Correct |
76 ms |
15980 KB |
Output is correct |
10 |
Correct |
77 ms |
15992 KB |
Output is correct |
11 |
Correct |
73 ms |
15956 KB |
Output is correct |
12 |
Correct |
73 ms |
15956 KB |
Output is correct |
13 |
Correct |
82 ms |
15984 KB |
Output is correct |
14 |
Correct |
76 ms |
15980 KB |
Output is correct |
15 |
Correct |
79 ms |
16076 KB |
Output is correct |
16 |
Correct |
75 ms |
15984 KB |
Output is correct |
17 |
Correct |
73 ms |
15980 KB |
Output is correct |
18 |
Correct |
77 ms |
15984 KB |
Output is correct |
19 |
Correct |
82 ms |
15984 KB |
Output is correct |
20 |
Correct |
84 ms |
15984 KB |
Output is correct |
21 |
Correct |
74 ms |
15988 KB |
Output is correct |
22 |
Correct |
77 ms |
15956 KB |
Output is correct |
23 |
Correct |
76 ms |
15956 KB |
Output is correct |
24 |
Correct |
80 ms |
15956 KB |
Output is correct |
25 |
Correct |
81 ms |
15956 KB |
Output is correct |
26 |
Correct |
81 ms |
15984 KB |
Output is correct |
27 |
Correct |
73 ms |
15956 KB |
Output is correct |
28 |
Correct |
80 ms |
15984 KB |
Output is correct |
29 |
Correct |
79 ms |
15988 KB |
Output is correct |
30 |
Correct |
85 ms |
15992 KB |
Output is correct |
31 |
Correct |
77 ms |
15956 KB |
Output is correct |
32 |
Correct |
80 ms |
15992 KB |
Output is correct |
33 |
Correct |
78 ms |
15988 KB |
Output is correct |
34 |
Correct |
76 ms |
15992 KB |
Output is correct |
35 |
Correct |
85 ms |
15992 KB |
Output is correct |
36 |
Correct |
85 ms |
15956 KB |
Output is correct |
37 |
Correct |
86 ms |
15996 KB |
Output is correct |
38 |
Correct |
75 ms |
15968 KB |
Output is correct |
39 |
Correct |
77 ms |
16000 KB |
Output is correct |
40 |
Correct |
115 ms |
15956 KB |
Output is correct |
41 |
Correct |
87 ms |
15996 KB |
Output is correct |
42 |
Correct |
75 ms |
15996 KB |
Output is correct |
43 |
Correct |
76 ms |
15956 KB |
Output is correct |
44 |
Correct |
81 ms |
15996 KB |
Output is correct |
45 |
Correct |
77 ms |
15956 KB |
Output is correct |
46 |
Correct |
86 ms |
15996 KB |
Output is correct |
47 |
Correct |
74 ms |
16008 KB |
Output is correct |
48 |
Correct |
83 ms |
16048 KB |
Output is correct |
49 |
Correct |
74 ms |
15956 KB |
Output is correct |
50 |
Correct |
77 ms |
16000 KB |
Output is correct |
51 |
Correct |
81 ms |
15988 KB |
Output is correct |
52 |
Correct |
82 ms |
15956 KB |
Output is correct |
53 |
Correct |
81 ms |
16000 KB |
Output is correct |
54 |
Correct |
110 ms |
15996 KB |
Output is correct |
55 |
Correct |
97 ms |
15956 KB |
Output is correct |
56 |
Correct |
113 ms |
16024 KB |
Output is correct |
57 |
Correct |
106 ms |
16028 KB |
Output is correct |
58 |
Correct |
122 ms |
16016 KB |
Output is correct |
59 |
Correct |
145 ms |
16020 KB |
Output is correct |
60 |
Correct |
117 ms |
16144 KB |
Output is correct |
61 |
Correct |
78 ms |
15992 KB |
Output is correct |
62 |
Correct |
82 ms |
16008 KB |
Output is correct |
63 |
Correct |
109 ms |
15968 KB |
Output is correct |
64 |
Correct |
80 ms |
15956 KB |
Output is correct |
65 |
Correct |
94 ms |
16016 KB |
Output is correct |
66 |
Correct |
99 ms |
16028 KB |
Output is correct |
67 |
Correct |
106 ms |
16020 KB |
Output is correct |
68 |
Correct |
180 ms |
16024 KB |
Output is correct |
69 |
Correct |
116 ms |
16024 KB |
Output is correct |