이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
const int NUM_BITS=41;
int arr[2000];
int n,a,b;
bool is_possible(ll mask){
vector<vector<bool>>dp(n+1,vector<bool>(n+1,false)); // dp[i][j] if we take the subarray arr[0..i] can we partition it into j groups so that all sums | mask == mask
dp[0][0]=true;
for(int i=0;i<=n;i++){
ll sum=0;
for(int j=i-1;j>=0;j--){
sum+=arr[j];
if((sum|mask)==mask){
for(int k=0;k<i;k++){
if(dp[j][k])
dp[i][k+1]=true;
}
}
}
}
for(int i=a;i<=b;i++){
if(dp[n][i])
return true;
}
return false;
}
void solve(){
cin>>n>>a>>b;
for(int i=0;i<n;i++)
cin>>arr[i];
ll mask=(1LL<<NUM_BITS)-1;
for(int i=NUM_BITS-1;i>=0;i--){
mask^=1LL<<i;
if(!is_possible(mask))
mask^=1LL<<i;
}
cout<<mask<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)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... |