# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
506072 | amukkalir | Bali Sculptures (APIO15_sculpture) | C++17 | 1095 ms | 16120 KiB |
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>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define se second
#define fi first
#define pb push_back
#define wek puts("wekwek")
#define wik puts("-------")
const int nax = 2e3;
const ll INF = (1ll<<42)-1;
int n, a, b;
int dp[nax+5][nax+5];
ll p[nax+5];
ll sum (int l, int r) {
return p[r] - p[l-1];
}
int f(int grup, int idx, ll x) {
if(grup > b) return 0;
if(idx == n+1) {
return (a <= grup && grup <= b);
}
int &ret = dp[grup][idx];
if(~ret) return ret;
ret = 0;
for(int j=idx; j<=n; j++) {
if((x | sum(idx,j)) == x) {
ret |= f(grup+1, j+1, x);
}
}
//cout << grup << " " << idx << " " << ret << endl;
return ret;
}
signed main () {
scanf("%d %d %d", &n, &a, &b);
for(int i=1; i<=n; i++) {
scanf("%lld", &p[i]);
p[i] += p[i-1];
//cout << i << " " << p[i] << endl;
}
ll lo = 0, hi = INF;
ll ans = hi;
while(lo <= hi) {
ll mid = (lo+hi)/2;
memset(dp, -1, sizeof dp);
//cout << bitset<64> (mid) << endl;
if(f(0, 1, mid)) {
ans = mid;
hi = mid-1;
} else {
lo = mid+1;
}
}
printf("%lld", ans);
}
/*
*/
Compilation message (stderr)
# | 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... |