#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define all(v) v.begin(), v.end()
#define bpc(x) __builtin_popcount(x)
#define endl "\n"
using namespace std;
const int sz = 2005; /// mind the sz
const ll inf = 1e18;
// using namespace __gnu_pbds;
// tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;
ll n, A, B, pr[sz], a[sz], ca;
ll dp[sz][sz], DP[sz];
bool rec(ll idx, ll blocks, ll bt){
if(idx == (n + 1)){
return (A <= blocks && blocks <= B);
}
if(dp[idx][blocks] != -1){return dp[idx][blocks];}
for(int j = idx + 1; j <= (n + 1); j++){
ll t = (pr[j - 1] - pr[idx - 1]);
if(((ca | t) >> bt << bt) == ca && rec(j, blocks + 1, bt)){
return dp[idx][blocks] = 1;
}
}
return dp[idx][blocks] = 0;
}
bool solveforaequalto1(ll bt){
ll i, j, ra;
vl DP(n + 1, inf);
DP[0] = 0;
for(i = 1; i <= n; i++){
for(j = i; j > 0; j--){
ra = pr[i] - pr[j - 1];
if((ca | ra) >> bt << bt == ca){
DP[i] = min(DP[i], DP[j - 1] + 1);
}
}
}
return DP[n] > B;
}
void solve(){
ll i, j;
cin >> n >> A >> B;
for(i = 1; i <= n; i++){
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
for(i = 60; i >= 0; i--){
// cout << i << ' ' << rec(1, 0, i) << endl;
if(A == 1){
ca |= (solveforaequalto1(i)) * (1ll << i);
}
else{
memset(dp, -1, sizeof(dp));
ca |= (!rec(1, 0, i)) * (1ll << i);
}
}
cout << ca << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp: In function 'bool rec(long long int, long long int, long long int)':
sculpture.cpp:31:36: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
31 | return dp[idx][blocks] = 1;
| ~~~~~~~~~~~~~~~~^~~
sculpture.cpp:34:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
34 | return dp[idx][blocks] = 0;
| ~~~~~~~~~~~~~~~~^~~
sculpture.cpp: In function 'void solve()':
sculpture.cpp:51:11: warning: unused variable 'j' [-Wunused-variable]
51 | ll i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
155 ms |
31916 KB |
Output is correct |
15 |
Correct |
148 ms |
31832 KB |
Output is correct |
16 |
Correct |
149 ms |
31920 KB |
Output is correct |
17 |
Correct |
152 ms |
31912 KB |
Output is correct |
18 |
Correct |
148 ms |
31912 KB |
Output is correct |
19 |
Correct |
146 ms |
31836 KB |
Output is correct |
20 |
Correct |
147 ms |
31832 KB |
Output is correct |
21 |
Correct |
159 ms |
31920 KB |
Output is correct |
22 |
Correct |
153 ms |
31932 KB |
Output is correct |
23 |
Correct |
149 ms |
31912 KB |
Output is correct |
24 |
Correct |
147 ms |
31916 KB |
Output is correct |
25 |
Correct |
150 ms |
31912 KB |
Output is correct |
26 |
Correct |
146 ms |
31836 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
154 ms |
31920 KB |
Output is correct |
15 |
Correct |
153 ms |
31920 KB |
Output is correct |
16 |
Correct |
153 ms |
31912 KB |
Output is correct |
17 |
Correct |
151 ms |
31920 KB |
Output is correct |
18 |
Correct |
154 ms |
31916 KB |
Output is correct |
19 |
Correct |
154 ms |
31836 KB |
Output is correct |
20 |
Correct |
158 ms |
31916 KB |
Output is correct |
21 |
Correct |
151 ms |
31916 KB |
Output is correct |
22 |
Correct |
155 ms |
31916 KB |
Output is correct |
23 |
Correct |
148 ms |
31920 KB |
Output is correct |
24 |
Correct |
148 ms |
31920 KB |
Output is correct |
25 |
Correct |
155 ms |
31920 KB |
Output is correct |
26 |
Correct |
148 ms |
31836 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
464 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
544 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
149 ms |
31916 KB |
Output is correct |
15 |
Correct |
147 ms |
31916 KB |
Output is correct |
16 |
Correct |
151 ms |
31916 KB |
Output is correct |
17 |
Correct |
149 ms |
31916 KB |
Output is correct |
18 |
Correct |
150 ms |
31832 KB |
Output is correct |
19 |
Correct |
150 ms |
31832 KB |
Output is correct |
20 |
Correct |
151 ms |
31916 KB |
Output is correct |
21 |
Correct |
156 ms |
31916 KB |
Output is correct |
22 |
Correct |
152 ms |
32088 KB |
Output is correct |
23 |
Correct |
151 ms |
31836 KB |
Output is correct |
24 |
Correct |
151 ms |
31880 KB |
Output is correct |
25 |
Correct |
153 ms |
31912 KB |
Output is correct |
26 |
Correct |
149 ms |
31916 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
428 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
464 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
344 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
149 ms |
31920 KB |
Output is correct |
65 |
Correct |
152 ms |
31912 KB |
Output is correct |
66 |
Correct |
156 ms |
31928 KB |
Output is correct |
67 |
Correct |
153 ms |
31844 KB |
Output is correct |
68 |
Correct |
148 ms |
31832 KB |
Output is correct |
69 |
Correct |
151 ms |
31928 KB |
Output is correct |
70 |
Correct |
149 ms |
31832 KB |
Output is correct |
71 |
Correct |
174 ms |
31832 KB |
Output is correct |
72 |
Correct |
148 ms |
31936 KB |
Output is correct |
73 |
Correct |
151 ms |
31928 KB |
Output is correct |
74 |
Correct |
150 ms |
31932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
372 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
348 KB |
Output is correct |
52 |
Correct |
12 ms |
344 KB |
Output is correct |
53 |
Correct |
23 ms |
504 KB |
Output is correct |
54 |
Correct |
35 ms |
348 KB |
Output is correct |
55 |
Correct |
34 ms |
348 KB |
Output is correct |
56 |
Correct |
138 ms |
764 KB |
Output is correct |
57 |
Correct |
139 ms |
348 KB |
Output is correct |
58 |
Correct |
127 ms |
508 KB |
Output is correct |
59 |
Correct |
138 ms |
520 KB |
Output is correct |
60 |
Correct |
133 ms |
348 KB |
Output is correct |
61 |
Correct |
1 ms |
344 KB |
Output is correct |
62 |
Correct |
19 ms |
344 KB |
Output is correct |
63 |
Correct |
35 ms |
348 KB |
Output is correct |
64 |
Correct |
35 ms |
344 KB |
Output is correct |
65 |
Correct |
67 ms |
348 KB |
Output is correct |
66 |
Correct |
102 ms |
508 KB |
Output is correct |
67 |
Correct |
168 ms |
348 KB |
Output is correct |
68 |
Correct |
149 ms |
600 KB |
Output is correct |
69 |
Correct |
130 ms |
512 KB |
Output is correct |