이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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... |