This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void main_program();
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
main_program();
}
using ll = long long;
int n, A, B;
vector<int> v;
bool check_normal(ll x){
vector<vector<int>> dp(n + 1, vector<int>(B + 1, 0));
dp[0][0] = 1;
for (int i = 0; i <= n; i++){
ll sum = 0;
for (int j = i + 1; j <= n; j++){
sum += v[j - 1];
if ((sum & x) == sum){
for (int blk = 0; blk < B; blk++){
dp[j][blk + 1] |= dp[i][blk];
}
}
}
}
for (int j = A; j <= B; j++){
if (dp[n][j]) return true;
}
return false;
}
bool check(ll x){
return check_normal(x);
}
void main_program(){
cin >> n >> A >> B;
v.resize(n);
for (int i = 0; i < n; i++) cin >> v[i];
ll ans = (1LL << 42) - 1;
for (int i = 41; i >= 0; i--){
if (check(ans ^ (1LL << i))) ans ^= (1LL << i);
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |