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;
typedef long long ll;
const int N = 2007;
int n, a, b, x[N];
namespace subtask4{
bool dp[N][N];
bool check(ll val){
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= b; j++){
ll sum = 0;
for(int k = i; k >= 1; k--){
sum += x[k];
if ((sum | val) == val)
dp[i][j] |= dp[k - 1][j - 1];
}
}
for(int i = a; i <= b; i++)
if (dp[n][i])
return 1;
return 0;
}
void solve(){
ll answer = (1ll << 41) - 1;
for(int i = 40; i >= 0; i--){
answer ^= (1ll << i);
if (!check(answer))
answer ^= (1ll << i);
}
cout << answer;
}
}
namespace subtask5{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
for(int i = 1; i <= n; i++)
cin >> x[i];
if (n <= 100)
subtask4::solve();
else
subtask5::solve();
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
# | 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... |