#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define se second
#define fi first
#define pb push_back
#define wek puts("wekwek")
#define wik puts("-------")
const int nax = 2e3;
const ll INF = (1ll<<42)-1;
int n, a, b;
int dp[nax+5][nax+5];
int memo[nax+5];
ll p[nax+5];
ll sum (int l, int r) {
return p[r] - p[l-1];
}
int f(int grup, int idx, ll x) {
if(grup > b) return 0;
if(idx == n+1) {
return (a <= grup && grup <= b);
}
int &ret = dp[grup][idx];
if(~ret) return ret;
ret = 0;
for(int j=idx; j<=n; j++) {
if((x | sum(idx,j)) == x) {
ret |= f(grup+1, j+1, x);
}
}
//cout << grup << " " << idx << " " << ret << endl;
return ret;
}
int rec(int idx, ll x) {
if(idx == n+1) return 0;
int &ret = memo[idx];
if(~ret) return ret;
ret = n+1;
for(int j=idx; j<=n; j++) {
if((x | sum(idx,j)) == x) {
ret = min(ret, 1 + rec(j+1, x));
}
}
return ret;
}
void solve() {
ll lo = 0, hi = INF;
ll ans = hi;
while(lo <= hi) {
ll mid = (lo+hi)/2;
memset(memo, -1, sizeof memo);
//cout << bitset<64> (mid) << endl;
if(rec(1, mid) <= b) {
ans = mid;
hi = mid-1;
} else {
lo = mid+1;
}
}
printf("%lld", ans);
exit(0);
}
signed main () {
scanf("%d %d %d", &n, &a, &b);
for(int i=1; i<=n; i++) {
scanf("%lld", &p[i]);
p[i] += p[i-1];
//cout << i << " " << p[i] << endl;
}
if(a==1) solve();
ll lo = 0, hi = INF;
ll ans = hi;
while(lo <= hi) {
ll mid = (lo+hi)/2;
memset(dp, -1, sizeof dp);
//cout << bitset<64> (mid) << endl;
if(f(0, 1, mid)) {
ans = mid;
hi = mid-1;
} else {
lo = mid+1;
}
}
printf("%lld", ans);
}
/*
*/
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | scanf("%d %d %d", &n, &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | scanf("%lld", &p[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
75 ms |
16008 KB |
Output is correct |
15 |
Correct |
74 ms |
15948 KB |
Output is correct |
16 |
Correct |
78 ms |
16008 KB |
Output is correct |
17 |
Correct |
74 ms |
16012 KB |
Output is correct |
18 |
Correct |
71 ms |
16004 KB |
Output is correct |
19 |
Correct |
76 ms |
16008 KB |
Output is correct |
20 |
Correct |
79 ms |
15948 KB |
Output is correct |
21 |
Correct |
75 ms |
15948 KB |
Output is correct |
22 |
Correct |
72 ms |
16004 KB |
Output is correct |
23 |
Correct |
73 ms |
16004 KB |
Output is correct |
24 |
Correct |
72 ms |
16008 KB |
Output is correct |
25 |
Correct |
79 ms |
15948 KB |
Output is correct |
26 |
Correct |
75 ms |
15948 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
76 ms |
16008 KB |
Output is correct |
15 |
Correct |
74 ms |
16004 KB |
Output is correct |
16 |
Correct |
75 ms |
16076 KB |
Output is correct |
17 |
Correct |
75 ms |
15984 KB |
Output is correct |
18 |
Correct |
87 ms |
16008 KB |
Output is correct |
19 |
Correct |
76 ms |
16008 KB |
Output is correct |
20 |
Correct |
73 ms |
16004 KB |
Output is correct |
21 |
Correct |
74 ms |
16012 KB |
Output is correct |
22 |
Correct |
73 ms |
16020 KB |
Output is correct |
23 |
Correct |
74 ms |
15948 KB |
Output is correct |
24 |
Correct |
75 ms |
16008 KB |
Output is correct |
25 |
Correct |
74 ms |
15948 KB |
Output is correct |
26 |
Correct |
73 ms |
15948 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
71 ms |
15948 KB |
Output is correct |
15 |
Correct |
72 ms |
16004 KB |
Output is correct |
16 |
Correct |
79 ms |
16008 KB |
Output is correct |
17 |
Correct |
72 ms |
15948 KB |
Output is correct |
18 |
Correct |
75 ms |
15948 KB |
Output is correct |
19 |
Correct |
86 ms |
15952 KB |
Output is correct |
20 |
Correct |
85 ms |
15948 KB |
Output is correct |
21 |
Correct |
74 ms |
15956 KB |
Output is correct |
22 |
Correct |
71 ms |
15948 KB |
Output is correct |
23 |
Correct |
74 ms |
16008 KB |
Output is correct |
24 |
Correct |
72 ms |
16004 KB |
Output is correct |
25 |
Correct |
73 ms |
16012 KB |
Output is correct |
26 |
Correct |
78 ms |
16004 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
208 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
2 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
216 KB |
Output is correct |
56 |
Correct |
0 ms |
204 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
1 ms |
204 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
98 ms |
16016 KB |
Output is correct |
65 |
Correct |
78 ms |
16008 KB |
Output is correct |
66 |
Correct |
77 ms |
16072 KB |
Output is correct |
67 |
Correct |
77 ms |
16008 KB |
Output is correct |
68 |
Correct |
78 ms |
16004 KB |
Output is correct |
69 |
Correct |
82 ms |
16016 KB |
Output is correct |
70 |
Correct |
79 ms |
16008 KB |
Output is correct |
71 |
Correct |
72 ms |
15948 KB |
Output is correct |
72 |
Correct |
82 ms |
16008 KB |
Output is correct |
73 |
Correct |
84 ms |
15948 KB |
Output is correct |
74 |
Correct |
81 ms |
15948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
256 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
2 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
304 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
1 ms |
204 KB |
Output is correct |
52 |
Correct |
13 ms |
352 KB |
Output is correct |
53 |
Correct |
9 ms |
368 KB |
Output is correct |
54 |
Correct |
29 ms |
364 KB |
Output is correct |
55 |
Correct |
23 ms |
332 KB |
Output is correct |
56 |
Correct |
54 ms |
332 KB |
Output is correct |
57 |
Correct |
49 ms |
440 KB |
Output is correct |
58 |
Correct |
81 ms |
416 KB |
Output is correct |
59 |
Correct |
69 ms |
324 KB |
Output is correct |
60 |
Correct |
84 ms |
460 KB |
Output is correct |
61 |
Correct |
1 ms |
204 KB |
Output is correct |
62 |
Correct |
13 ms |
364 KB |
Output is correct |
63 |
Correct |
34 ms |
304 KB |
Output is correct |
64 |
Correct |
25 ms |
332 KB |
Output is correct |
65 |
Correct |
26 ms |
400 KB |
Output is correct |
66 |
Correct |
37 ms |
440 KB |
Output is correct |
67 |
Correct |
60 ms |
440 KB |
Output is correct |
68 |
Correct |
101 ms |
440 KB |
Output is correct |
69 |
Correct |
45 ms |
332 KB |
Output is correct |