#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;
const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;
template <class T> using V = vector<T>; // from yosupo
template <class T> using VV = V<V<T>>; // from yosupo
template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
x = (x > y ? y : x);
}
int n;
int A, B;
int a[N];
int ans;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
void dfs(int now, int cur, int cursum, int partition) {
if(now == n) {
if(cur) {
partition++;
cursum |= cur;
}
if(partition >= A && partition <= B) {
ckmi(ans, cursum);
//debug(ans, partition);
}
return;
}
dfs(now + 1, cur + a[now], cursum, partition);
dfs(now + 1, 0, (cur + a[now]) | cursum, partition + 1);
}
void solve() {
ans = INT_MAX;
cin >> n;
cin >> A >> B;
forn(i, n) cin >> a[i];
dfs(0, 0, 0, 0);
cout << ans << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
328 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
7 ms |
204 KB |
Output is correct |
10 |
Correct |
7 ms |
204 KB |
Output is correct |
11 |
Correct |
7 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
320 KB |
Output is correct |
13 |
Correct |
7 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
7 ms |
204 KB |
Output is correct |
22 |
Correct |
7 ms |
204 KB |
Output is correct |
23 |
Correct |
7 ms |
320 KB |
Output is correct |
24 |
Correct |
7 ms |
204 KB |
Output is correct |
25 |
Correct |
7 ms |
204 KB |
Output is correct |
26 |
Correct |
7 ms |
204 KB |
Output is correct |
27 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
324 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
7 ms |
328 KB |
Output is correct |
10 |
Correct |
9 ms |
316 KB |
Output is correct |
11 |
Correct |
9 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
204 KB |
Output is correct |
13 |
Correct |
7 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
7 ms |
324 KB |
Output is correct |
22 |
Correct |
7 ms |
204 KB |
Output is correct |
23 |
Correct |
7 ms |
204 KB |
Output is correct |
24 |
Correct |
7 ms |
320 KB |
Output is correct |
25 |
Correct |
7 ms |
328 KB |
Output is correct |
26 |
Correct |
7 ms |
324 KB |
Output is correct |
27 |
Correct |
13 ms |
204 KB |
Output is correct |
28 |
Correct |
199 ms |
320 KB |
Output is correct |
29 |
Execution timed out |
1076 ms |
204 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
7 ms |
204 KB |
Output is correct |
9 |
Correct |
7 ms |
204 KB |
Output is correct |
10 |
Correct |
9 ms |
320 KB |
Output is correct |
11 |
Correct |
7 ms |
328 KB |
Output is correct |
12 |
Correct |
7 ms |
204 KB |
Output is correct |
13 |
Correct |
7 ms |
204 KB |
Output is correct |
14 |
Correct |
13 ms |
332 KB |
Output is correct |
15 |
Correct |
195 ms |
204 KB |
Output is correct |
16 |
Execution timed out |
1085 ms |
204 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
10 ms |
320 KB |
Output is correct |
9 |
Correct |
8 ms |
204 KB |
Output is correct |
10 |
Correct |
7 ms |
204 KB |
Output is correct |
11 |
Correct |
7 ms |
332 KB |
Output is correct |
12 |
Correct |
7 ms |
324 KB |
Output is correct |
13 |
Correct |
7 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
204 KB |
Output is correct |
21 |
Correct |
7 ms |
204 KB |
Output is correct |
22 |
Correct |
7 ms |
204 KB |
Output is correct |
23 |
Correct |
7 ms |
204 KB |
Output is correct |
24 |
Correct |
7 ms |
204 KB |
Output is correct |
25 |
Correct |
7 ms |
332 KB |
Output is correct |
26 |
Correct |
7 ms |
204 KB |
Output is correct |
27 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
8 ms |
324 KB |
Output is correct |
9 |
Correct |
7 ms |
204 KB |
Output is correct |
10 |
Correct |
9 ms |
224 KB |
Output is correct |
11 |
Correct |
7 ms |
320 KB |
Output is correct |
12 |
Correct |
7 ms |
204 KB |
Output is correct |
13 |
Correct |
7 ms |
324 KB |
Output is correct |
14 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |