#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 2002, lgn = 33;
int y[mxn], p[mxn];
int n, a, b;
bool check(int mask) {
vector<int> dp(n + 1, n + 1);
dp[0] = 0;
for(int i = 1; i <= n; i++)
for(int j = 0; j < i; j++)
if((mask | (p[i] - p[j])) == mask)
dp[i] = min(dp[i], dp[j] + 1);
return dp[n] <= b;
}
bool fix(int mask) {
vector<vector<bool>> dp(n + 1, vector<bool>(n + 1));
dp[0][0] = true;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= i; j++)
for(int k = 0; k < i; k++)
if((mask | (p[i] - p[k])) == mask)
dp[i][j] = dp[k][j - 1];
for(int i = a; i <= b; i++)
if(dp[n][i])
return true;
return false;
}
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
#ifdef saarang
freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
#endif
cin >> n >> a >> b;
for(int i = 1; i <= n; i++)
cin >> y[i];
for(int i = 1; i <= n; i++)
p[i] = p[i - 1] + y[i];
int ans = (1 << lgn) - 1;
for(int bit = lgn - 1; bit >= 0; bit--) {
if(a == 1) {
if(check(ans ^ (1 << bit)))
ans ^= (1 << bit);
}
else {
if(fix(ans ^ (1 << bit)))
ans ^= (1 << bit);
}
}
cout << ans << '\n';
return 0;
}
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:45:21: warning: left shift count >= width of type [-Wshift-count-overflow]
45 | int ans = (1 << lgn) - 1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |