This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 110, Max = 2010, mod = 1e9 + 7, Log = 50;
int a[maxn], n, L, R;
int dp[Max];
bitset<maxn> bs[maxn];
bool ok(ll deny){
if(L == 1){
for(int i = 0; i < n; i++){
dp[i + 1] = n + 10;
ll sm = 0;
for(int j = i; j >= 0; j--){
sm+= a[j];
if(sm & deny)
continue;
dp[i + 1] = min(dp[i + 1], 1 + dp[j]);
}
}
if(dp[n] <= R)
return 1;
}
else{
bs[0][0] = 1;
for(int i = 0; i < n; i++){
bs[i + 1] = 0;
ll sm = 0;
for(int j = i; j >= 0; j--){
sm+= a[j];
if(sm & deny)
continue;
bs[i+1] = bs[i+1] | (bs[j]<<1);
}
}
for(int i = L; i <= R; i++){
if(bs[n][i])
return 1;
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
cin >> n >> L >> R;
for(int i = 0; i < n; i++){
cin >> a[i];
}
ll ans = (1ll<<Log) - 1;
for(int bt = Log-1; bt >= 0; bt--){
ans^= 1ll<<bt;
if(ok(((1ll<<Log) - 1) ^ ans) == 0)
ans^= 1ll<<bt;
}
return cout << ans << endl, 0;
}
# | 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... |