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>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
int n, a, b;
ll ans = 1e18;
vector<int> v(n+1);
vector<ll> pref(n+1);
void f(int pos, ll res, int groups) {
if(groups > b) return ;
if(pos == n + 1 && a <= groups) {
ans = min(ans, res);
return ;
}
ll sum = 0;
for(int i=pos; i<=n; i++) {
sum += v[i];
f(i+1, res | sum, groups + 1);
}
}
int32_t main() {
cin >> n >> a >> b;
v.resize(n+1);
pref.resize(n+1);
for(int i=1; i<=n; i++) cin >> v[i], pref[i] = pref[i-1] + v[i];
auto query = [&](int l, int r) { return pref[r] - pref[l-1]; };
// if(a == 1) {
// ll mask = 0;
// for(int bit=51; bit>=0; bit--) {
// ll mask2 = mask | (1ll << bit);
// vector<int> dp(n+1, 1e9);
// dp[0] = 0;
// for(int i=1; i<=n; i++) {
// for(int j=i; j>=1; j--) {
// if(query(j, i) & mask2) continue;
// dp[i] = min(dp[i], dp[j-1] + 1);
// }
// }
// if(dp[n] <= b) mask |= (1ll << bit);
// }
// mask ^= ((1ll << 52) - 1);
// cout << mask << '\n';
// return 0;
// }
if(n <= 20) {
f(1, 0, 0);
cout << ans << '\n';
return 0;
}
return 0;
}
Compilation message (stderr)
sculpture.cpp: In function 'int32_t main()':
sculpture.cpp:49:10: warning: variable 'query' set but not used [-Wunused-but-set-variable]
49 | auto query = [&](int l, int r) { return pref[r] - pref[l-1]; };
| ^~~~~
# | 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... |