#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int N = (1<<18) +1, inf = 1e18+200;
//int mod = 998244353;
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
void solve(){
int n, a, b;
cin >> n >> a >> b;
vector<int> v(n);
for(int &i:v)cin >> i;
int ans = inf;
for(int ms = 0; ms < (1<<n); ms++){
int cn = __builtin_popcount(ms)+1;
if(cn < a || cn > b || (ms>>(n-1)) & 1)continue;
int tot = 0;
int res = 0;
for(int i = 0; i < n; i++){
res += v[i];
if((ms >> i) & 1){
tot |= res;
res = 0;
}
}
tot |= res;
chmin(ans, tot);
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
456 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
27 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
26 ms |
452 KB |
Output is correct |
34 |
Correct |
32 ms |
344 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
31 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
4 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
464 KB |
Output is correct |
24 |
Correct |
3 ms |
604 KB |
Output is correct |
25 |
Correct |
5 ms |
348 KB |
Output is correct |
26 |
Correct |
27 ms |
348 KB |
Output is correct |
27 |
Correct |
69 ms |
848 KB |
Output is correct |
28 |
Correct |
204 ms |
432 KB |
Output is correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
348 KB |
Output is correct |
14 |
Correct |
63 ms |
344 KB |
Output is correct |
15 |
Correct |
204 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
33 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
5 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
460 KB |
Output is correct |
25 |
Correct |
5 ms |
348 KB |
Output is correct |
26 |
Correct |
27 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
26 ms |
456 KB |
Output is correct |
34 |
Correct |
37 ms |
344 KB |
Output is correct |
35 |
Correct |
3 ms |
348 KB |
Output is correct |
36 |
Correct |
33 ms |
432 KB |
Output is correct |
37 |
Correct |
62 ms |
348 KB |
Output is correct |
38 |
Correct |
205 ms |
344 KB |
Output is correct |
39 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
344 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
29 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
26 ms |
348 KB |
Output is correct |
21 |
Correct |
34 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
32 ms |
424 KB |
Output is correct |
24 |
Correct |
73 ms |
432 KB |
Output is correct |
25 |
Correct |
204 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |