#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
const long long INF = 1e18;
int n, a, b, p[N];
long long ans, sum[N], dp[N];
bool check[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) cin >> p[i], sum[i] = sum[i-1] + p[i];
if(a == 1) {
for(int pw = log2(sum[n]); pw >= 0; pw--) {
fill(dp+1, dp+n+1, INF);
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
if(!(sum[i] - sum[j] & (ans | 1 << pw))) dp[i] = min(dp[j] + 1, dp[i]);
}
if(dp[n] <= b) ans |= 1 << pw;
}
} else {
for(int pw = log2(sum[n]); pw >= 0; pw--) {
check[0][0] = true;
for(int k = 1; k <= b; k++) {
for(int i = 1; i <= n; i++) for(int j = 0; j < i; j++) {
if(!(sum[i] - sum[j] & (ans | 1 << pw))) check[i][k] |= check[j][k-1];
}
}
for(int k = a; k <= b; k++) if(check[n][k]) {
ans |= 1 << pw;
break;
}
}
}
cout << (1 << int(log2(sum[n])+1)) - 1 - ans;
}
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:18:17: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
if(!(sum[i] - sum[j] & (ans | 1 << pw))) dp[i] = min(dp[j] + 1, dp[i]);
^
sculpture.cpp:27:18: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
if(!(sum[i] - sum[j] & (ans | 1 << pw))) check[i][k] |= check[j][k-1];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6140 KB |
Output is correct |
2 |
Correct |
0 ms |
6140 KB |
Output is correct |
3 |
Correct |
0 ms |
6140 KB |
Output is correct |
4 |
Correct |
0 ms |
6140 KB |
Output is correct |
5 |
Correct |
0 ms |
6140 KB |
Output is correct |
6 |
Correct |
0 ms |
6140 KB |
Output is correct |
7 |
Correct |
0 ms |
6140 KB |
Output is correct |
8 |
Correct |
0 ms |
6140 KB |
Output is correct |
9 |
Correct |
0 ms |
6140 KB |
Output is correct |
10 |
Correct |
0 ms |
6140 KB |
Output is correct |
11 |
Correct |
0 ms |
6140 KB |
Output is correct |
12 |
Correct |
0 ms |
6140 KB |
Output is correct |
13 |
Correct |
0 ms |
6140 KB |
Output is correct |
14 |
Incorrect |
0 ms |
6140 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6140 KB |
Output is correct |
2 |
Correct |
0 ms |
6140 KB |
Output is correct |
3 |
Correct |
0 ms |
6140 KB |
Output is correct |
4 |
Correct |
0 ms |
6140 KB |
Output is correct |
5 |
Correct |
0 ms |
6140 KB |
Output is correct |
6 |
Correct |
0 ms |
6140 KB |
Output is correct |
7 |
Correct |
0 ms |
6140 KB |
Output is correct |
8 |
Correct |
0 ms |
6140 KB |
Output is correct |
9 |
Correct |
0 ms |
6140 KB |
Output is correct |
10 |
Correct |
0 ms |
6140 KB |
Output is correct |
11 |
Correct |
0 ms |
6140 KB |
Output is correct |
12 |
Correct |
0 ms |
6140 KB |
Output is correct |
13 |
Correct |
0 ms |
6140 KB |
Output is correct |
14 |
Incorrect |
0 ms |
6140 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6140 KB |
Output is correct |
2 |
Correct |
0 ms |
6140 KB |
Output is correct |
3 |
Correct |
0 ms |
6140 KB |
Output is correct |
4 |
Correct |
0 ms |
6140 KB |
Output is correct |
5 |
Correct |
0 ms |
6140 KB |
Output is correct |
6 |
Correct |
0 ms |
6140 KB |
Output is correct |
7 |
Correct |
0 ms |
6140 KB |
Output is correct |
8 |
Correct |
0 ms |
6140 KB |
Output is correct |
9 |
Correct |
0 ms |
6140 KB |
Output is correct |
10 |
Correct |
0 ms |
6140 KB |
Output is correct |
11 |
Correct |
0 ms |
6140 KB |
Output is correct |
12 |
Correct |
0 ms |
6140 KB |
Output is correct |
13 |
Correct |
0 ms |
6140 KB |
Output is correct |
14 |
Correct |
0 ms |
6140 KB |
Output is correct |
15 |
Correct |
0 ms |
6140 KB |
Output is correct |
16 |
Correct |
0 ms |
6140 KB |
Output is correct |
17 |
Correct |
0 ms |
6140 KB |
Output is correct |
18 |
Correct |
0 ms |
6140 KB |
Output is correct |
19 |
Correct |
0 ms |
6140 KB |
Output is correct |
20 |
Correct |
0 ms |
6140 KB |
Output is correct |
21 |
Correct |
0 ms |
6140 KB |
Output is correct |
22 |
Correct |
0 ms |
6140 KB |
Output is correct |
23 |
Correct |
0 ms |
6140 KB |
Output is correct |
24 |
Correct |
0 ms |
6140 KB |
Output is correct |
25 |
Correct |
0 ms |
6140 KB |
Output is correct |
26 |
Correct |
0 ms |
6140 KB |
Output is correct |
27 |
Correct |
0 ms |
6140 KB |
Output is correct |
28 |
Correct |
0 ms |
6140 KB |
Output is correct |
29 |
Correct |
0 ms |
6140 KB |
Output is correct |
30 |
Correct |
0 ms |
6140 KB |
Output is correct |
31 |
Correct |
0 ms |
6140 KB |
Output is correct |
32 |
Correct |
0 ms |
6140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6140 KB |
Output is correct |
2 |
Correct |
0 ms |
6140 KB |
Output is correct |
3 |
Correct |
0 ms |
6140 KB |
Output is correct |
4 |
Correct |
0 ms |
6140 KB |
Output is correct |
5 |
Correct |
0 ms |
6140 KB |
Output is correct |
6 |
Correct |
0 ms |
6140 KB |
Output is correct |
7 |
Correct |
0 ms |
6140 KB |
Output is correct |
8 |
Correct |
0 ms |
6140 KB |
Output is correct |
9 |
Correct |
0 ms |
6140 KB |
Output is correct |
10 |
Correct |
0 ms |
6140 KB |
Output is correct |
11 |
Correct |
0 ms |
6140 KB |
Output is correct |
12 |
Correct |
0 ms |
6140 KB |
Output is correct |
13 |
Correct |
0 ms |
6140 KB |
Output is correct |
14 |
Incorrect |
0 ms |
6140 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
6140 KB |
Output is correct |
2 |
Correct |
0 ms |
6140 KB |
Output is correct |
3 |
Correct |
0 ms |
6140 KB |
Output is correct |
4 |
Correct |
0 ms |
6140 KB |
Output is correct |
5 |
Correct |
0 ms |
6140 KB |
Output is correct |
6 |
Correct |
0 ms |
6140 KB |
Output is correct |
7 |
Correct |
0 ms |
6140 KB |
Output is correct |
8 |
Correct |
0 ms |
6140 KB |
Output is correct |
9 |
Correct |
0 ms |
6140 KB |
Output is correct |
10 |
Correct |
0 ms |
6140 KB |
Output is correct |
11 |
Correct |
0 ms |
6140 KB |
Output is correct |
12 |
Correct |
0 ms |
6140 KB |
Output is correct |
13 |
Correct |
0 ms |
6140 KB |
Output is correct |
14 |
Incorrect |
0 ms |
6140 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |