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 <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
ll n, a, b, x[1001], ans = 1e18;
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 0; i < ( 1 << n ); i++ )
{
ll s = 0, k = -1, res = 0, seg = 1;
for (int j = 0; j < n; j++)
{
if ( (i & (1 << j)) )
{
if ( k == 0 && k != -1 )
{
k = 1;
res |= s;
s = x[j + 1];
seg++;
} else {
k = 1;
s += x[j + 1];
}
} else {
if ( k == 0 || k == -1 )
{
s += x[j + 1];
k = 0;
}
else {
res |= s;
s = x[j + 1];
k = 0;
seg++;
}
}
}
res |= s;
if (seg <= b && seg >= a )
{
ans = min(ans, res);
}
}
cout << ans;
}
/*
10 1 9
4 51 23 24 61 83 35 79 82 71
*/
# | 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... |