# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978746 | SmuggingSpun | Bali Sculptures (APIO15_sculpture) | C++14 | 35 ms | 756 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>
#define taskname "sculpture"
using namespace std;
typedef long long ll;
const int INF = 1e9;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
int n, a, b;
vector<int>y;
namespace sub1{
void solve(){
ll ans = LLONG_MAX;
for(int mask = (1 << n) - 2; mask > -1; mask -= 2){
int cnt_1 = __builtin_popcount(mask) + 1;
if(a <= cnt_1 && cnt_1 <= b){
ll value = 0, sum = 0;
for(int i = 0; i < n; ){
if(1 << i & mask){
value |= sum;
sum = 0;
}
sum += y[++i];
}
minimize(ans, value | sum);
}
}
cout << ans;
}
}
namespace sub2{
const int LIM = 512;
const int lim = 105;
bitset<LIM>dp[2][lim];
void solve(){
bool cur = true, pre = false;
int ans = LIM;
for(int i = 0; i <= n; i++){
dp[cur][i].reset();
}
dp[cur][n + 1].set(0);
for(int i = 1; i <= b; i++){
swap(cur, pre);
for(int j = 0; j <= n; j++){
dp[cur][j].reset();
}
for(int j = 1; j <= n; j++){
for(int k = j, sum = 0; k <= n; k++){
sum += y[k];
for(int value = 0; value < LIM; value++){
if(dp[pre][k + 1].test(value)){
dp[cur][j].set(value | sum);
}
}
}
}
if(i >= a){
for(int j = 0; j < ans; j++){
if(dp[cur][1].test(j)){
ans = j;
break;
}
}
}
}
cout << ans << "\n";
}
}
namespace sub3{
const int LIM = 2048;
void solve(){
for(int i = 1; i < LIM; i++){
vector<int>dp(n + 2, INF);
dp[n + 1] = 0;
for(int j = n; j > 0; j--){
for(int k = j, sum = 0; k <= n; k++){
if(((sum += y[k]) & i) == sum){
minimize(dp[j], dp[k + 1] + 1);
}
}
}
if(dp[1] < b){
cout << i;
break;
}
}
}
}
namespace sub45{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> a >> b;
y.resize(n + 1);
for(int i = 1; i <= n; i++){
cin >> y[i];
}
if(n <= 20){
sub1::solve();
}
else if(n <= 50 && *max_element(y.begin() + 1, y.end()) <= 10){
sub2::solve();
}
else if(n <= 100 && *max_element(y.begin() + 1, y.end()) <= 20){
sub3::solve();
}
else{
sub45::solve();
}
}
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... |