#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,a,b;
cin>>n>>a>>b;
int it[n];
for(int i=0;i<n;i++){
cin>>it[i];
}
int dp[n][n][33];
memset(dp,0,sizeof(dp));
/* vector<int> mm[33];
vector<int> nn[33];
for(int mask=0;mask<33;mask++){
for(int submask = mask; ; submask = (submask - 1) & mask) {
mm[mask].pb(submask);
nn[submask].pb(mask);
if(submask == 0) break;
}
}*/
dp[0][0][it[0]]=1;
/*for(int i=0;i<mm[it[0]].size();i++){
dp[0][0][mm[it[0]]][i]=1;
}*/
int pre[n];
pre[0]=it[0];
for(int i=1;i<n;i++){
pre[i]=pre[i-1]+it[i];
}
for(int i=1;i<n;i++){
for(int j=0;j<i+1;j++){
if(j==0){
dp[i][0][pre[i]]=1;
/*if(pre[i]==0){
//cout<<i<<" "<<j<<endl;
}*/
continue;
}
for(int k=0;k<i;k++){
for(int l=0;l<33;l++){
if(dp[k][j-1][l]==1){
int no=(pre[i]-pre[k])|l;
/*if(no==0){
//cout<<"NNNNNNNNNNN"<<endl;
}*/
dp[i][j][no]=1;
// //cout<<no<<endl;
/*if(i==n-1){
//cout<<no<<endl;
}*/
}
}
}
}
// //cout<<dp[5][1][0]<<":::::::::::::::::"<<endl;
}
int ma=33;
for(int i=a-1;i<b;i++){
for(int j=0;j<33;j++){
////cout<<n-1<<" "<<i<<" "<<j<<" "<<dp[n-1][i][j]<<endl;
if(dp[n-1][i][j]==1){
/*if(j<ma){
//cout<<i<<" "<<j<<endl;
}*/
ma=min(ma,j);
}
}
}
cout<<ma<<endl;
/*int nno=8|3;
//cout<<nno<<endl;
*/
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
380 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |