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>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define pb push_back
#define el '\n'
#define mpair make_pair
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define fi first
#define se second
/* Author: Pham Gia Phuoc */
const ll MOD = (ll)(1e9) + 1LL * 19972207;
template <class T1, class T2>
void add(T1 &a, T2 b){
a += b;
if(a >= MOD) a -= MOD;
}
template <class T1, class T2>
void sub(T1 &a, T2 b){
a -= b;
if(a < 0) a += MOD;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if(a > b){a = b; return true;} return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if(a < b){a = b; return true;} return false;
}
/** END OF TEMPLATE. DRINK A CUP OF COFFEE BEFORE READING MY CODE **/
const int MAX = 2010;
const ll INF = (ll) 1e18 + 67LL;
const int oo = (int)(1e9 + 7);
const int NUM_BIT = 62;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
int N, A, B;
long long ages[MAX];
void init(){
cin >> N >> A >> B;
FOR(i, 1, N) cin >> ages[i];
}
namespace subtask1{
bool check(){
return N <= 20;
}
long long solve(){
long long ans = INF;
for(int mask = 0; mask < MASK(N); mask++){
if(__builtin_popcount(mask) == 0) continue;
int cntGroup = __builtin_popcount(mask) + (BIT(mask, N - 1) == 1 ? 0 : 1);
if(cntGroup < A || cntGroup > B) continue;
long long sum = 0, sumor = -1;
for(int i = 0; i < N; i++){
sum += ages[i + 1];
if(BIT(mask, i)){
sumor = (sumor == -1) ? sum : (sumor | sum);
sum = 0;
}
}
if(!BIT(mask, N - 1)){
// sum += ages[N];
sumor = (sumor == -1) ? sum : (sumor | sum);
}
minimize(ans, sumor);
}
return ans;
}
}
void solve(){
if(subtask1::check()){cout << subtask1::solve(); return;}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test "test"
srand(time(0));
int t = 1;
while(t--){
// gen();
init();
solve();
}
return 0;
}
/*** ROAD TO VOI 2025 ***/
# | 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... |