#include <iostream>
#include <vector>
#include <algorithm>
#define upmax(a, b) a = max(a, b);
#define upmin(a, b) a = min(a, b);
#define pr(x) cout << x << endl;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
const ll inf = 1e18;
ll n, a, b;
vll arr;
ll ans;
void brute(vll& div, ll ind)
{
if (ind == n) {
if (div.size() < a || div.size() > b) return;
ll res = 0;
ll cursum = 0;
ll p = 0;
for (ll i = 0; i < n; i++) {
cursum += arr[i];
if (p < div.size() && div[p] == i) {
res |= cursum;
p++;
cursum = 0;
}
}
res |= cursum;
upmin(ans, res);
return;
}
div.push_back(ind);
if(ind < n-1) brute(div, ind + 1);
div.pop_back();
brute(div, ind + 1);
}
int main()
{
cin >> n >> a >> b;
arr.resize(n);
for (ll i = 0; i < n; i++) cin >> arr[i];
ans = inf;
vll div;
brute(div, 0);
pr(ans);
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp: In function 'void brute(vll&, ll)':
sculpture.cpp:22:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
22 | if (div.size() < a || div.size() > b) return;
| ~~~~~~~~~~~^~~
sculpture.cpp:22:36: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
22 | if (div.size() < a || div.size() > b) return;
| ~~~~~~~~~~~^~~
sculpture.cpp:28:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (p < div.size() && div[p] == i) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
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 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |