#include <bits/stdc++.h>
#define stop system("pause")
#define INP freopen("balance.in","r",stdin)
#define OUTP freopen("balance.out","w",stdout)
#define int long long
using namespace std;
int n, a, b;
vector<int> v;
int dp[2001];
int dp2[101][101];
bool eq(int x, int mask){
//cout << "qwe " << x << ' ' << mask << ' ' << (x & mask) << endl;
return (x & mask) == 0;
}
bool bit(int x, int need){
return x & (1ll << need);
}
bool check1(int mask, int dig){
for(int i = 0; i < n;i++){
dp[i] = -1;
int mnres = INT_MAX;
int sum = 0;
for(int j = i; j >= 0;j--){
sum+=v[j];
if(eq(sum, mask) && !bit(sum, dig)){
if(i == 0)mnres = 1;
else{
if(dp[j - 1] == -1)continue;
mnres = min(mnres, dp[j - 1] + 1);
}
}
}
if(mnres!=INT_MAX){
dp[i] = mnres;
}
}
if(dp[n - 1] == -1){
return 0;
}
if(dp[n - 1] > b)return 0;
return 1;
}
bool check2(int mask, int dig){
for(int k = 1; k <= b;k++){
for(int i = 0; i < n;i++){
int sum = 0;
dp2[i][k] = -1;
for(int j = i; j >= 0;j--){
sum+=v[j];
if(eq(sum, mask) && !bit(sum, dig)){
if(k == 1){
if(j!=0)continue;
dp2[i][k] = 1;
continue;
}
if(j == 0 && k!=1)continue;
if(dp2[j - 1][k - 1] == -1)continue;
dp2[i][k] = 1;
}
}
}
}
for(int k = a; k <= b;k++){
if(dp2[n - 1][k] != -1)return 1;
}
return 0;
}
main(){
ios_base::sync_with_stdio(0);
cin >> n >> a >> b;
for(int i = 0; i < n;i++){
int x; cin >> x;
v.push_back(x);
}
int mask = 0;
int ans = 0;
//cout << "che " << (1 << 30) << endl;
for(int b = 50; b >= 0;b--){
mask^=(1ll << b);
bool f = (n <= 100 ? check2(mask, b) : check1(mask, b));
if(!f){
//cout << "bad " << endl;
ans+=(1ll << b);
mask^=(1ll << b);
}
}
cout << ans;
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp:76:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
76 | main(){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
396 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
396 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
4 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
3 ms |
364 KB |
Output is correct |
22 |
Correct |
3 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
3 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
364 KB |
Output is correct |
26 |
Correct |
7 ms |
364 KB |
Output is correct |
27 |
Correct |
22 ms |
492 KB |
Output is correct |
28 |
Correct |
45 ms |
364 KB |
Output is correct |
29 |
Correct |
45 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
22 ms |
364 KB |
Output is correct |
32 |
Correct |
34 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
236 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
3 ms |
364 KB |
Output is correct |
42 |
Correct |
3 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
3 ms |
364 KB |
Output is correct |
45 |
Correct |
3 ms |
364 KB |
Output is correct |
46 |
Correct |
2 ms |
364 KB |
Output is correct |
47 |
Correct |
3 ms |
364 KB |
Output is correct |
48 |
Correct |
3 ms |
364 KB |
Output is correct |
49 |
Correct |
7 ms |
364 KB |
Output is correct |
50 |
Correct |
22 ms |
364 KB |
Output is correct |
51 |
Correct |
44 ms |
364 KB |
Output is correct |
52 |
Correct |
43 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
364 KB |
Output is correct |
54 |
Correct |
22 ms |
364 KB |
Output is correct |
55 |
Correct |
38 ms |
364 KB |
Output is correct |
56 |
Correct |
3 ms |
364 KB |
Output is correct |
57 |
Correct |
6 ms |
364 KB |
Output is correct |
58 |
Correct |
16 ms |
492 KB |
Output is correct |
59 |
Correct |
32 ms |
364 KB |
Output is correct |
60 |
Correct |
30 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
38 ms |
364 KB |
Output is correct |
63 |
Correct |
37 ms |
364 KB |
Output is correct |
64 |
Correct |
34 ms |
364 KB |
Output is correct |
65 |
Correct |
3 ms |
364 KB |
Output is correct |
66 |
Correct |
2 ms |
364 KB |
Output is correct |
67 |
Correct |
6 ms |
364 KB |
Output is correct |
68 |
Correct |
19 ms |
492 KB |
Output is correct |
69 |
Correct |
34 ms |
364 KB |
Output is correct |
70 |
Correct |
29 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
38 ms |
492 KB |
Output is correct |
73 |
Correct |
30 ms |
364 KB |
Output is correct |
74 |
Correct |
27 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
5 ms |
364 KB |
Output is correct |
29 |
Correct |
3 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
8 ms |
364 KB |
Output is correct |
37 |
Correct |
22 ms |
364 KB |
Output is correct |
38 |
Correct |
44 ms |
364 KB |
Output is correct |
39 |
Correct |
43 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
22 ms |
364 KB |
Output is correct |
42 |
Correct |
33 ms |
364 KB |
Output is correct |
43 |
Correct |
3 ms |
492 KB |
Output is correct |
44 |
Correct |
6 ms |
364 KB |
Output is correct |
45 |
Correct |
16 ms |
364 KB |
Output is correct |
46 |
Correct |
33 ms |
364 KB |
Output is correct |
47 |
Correct |
29 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
39 ms |
364 KB |
Output is correct |
50 |
Correct |
37 ms |
364 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
9 ms |
492 KB |
Output is correct |
53 |
Correct |
13 ms |
364 KB |
Output is correct |
54 |
Correct |
23 ms |
364 KB |
Output is correct |
55 |
Correct |
22 ms |
364 KB |
Output is correct |
56 |
Correct |
80 ms |
364 KB |
Output is correct |
57 |
Correct |
81 ms |
364 KB |
Output is correct |
58 |
Correct |
79 ms |
492 KB |
Output is correct |
59 |
Correct |
81 ms |
364 KB |
Output is correct |
60 |
Correct |
85 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
13 ms |
364 KB |
Output is correct |
63 |
Correct |
23 ms |
364 KB |
Output is correct |
64 |
Correct |
22 ms |
364 KB |
Output is correct |
65 |
Correct |
41 ms |
364 KB |
Output is correct |
66 |
Correct |
61 ms |
492 KB |
Output is correct |
67 |
Correct |
81 ms |
364 KB |
Output is correct |
68 |
Correct |
85 ms |
384 KB |
Output is correct |
69 |
Correct |
84 ms |
512 KB |
Output is correct |