Submission #43253

#TimeUsernameProblemLanguageResultExecution timeMemory
43253hatuank97lhpBali Sculptures (APIO15_sculpture)C++14
100 / 100
97 ms752 KiB
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2005;
LL n,sum[N], a,b,x, dp[N] ;
bool ok1( LL Mask ) {
    memset(dp,0,sizeof(dp));
    for(int i = 1; i <= n; ++ i) {
        dp[i] = b + 1;
        for(int j = 0; j < i; ++ j) {
            if( ((sum[i] - sum[j]) & ~Mask) == 0 ) {
                dp[i] = min( dp[i], dp[j] + 1 );
            }
        }
    }

    if( dp[n] <= b ) return 1;
    return 0;

}

bool dp2[105][105];

bool ok2(LL Mask) {
    memset(dp2,0,sizeof(dp2));
    dp2[0][0] = 1;
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= b; ++ j) {
            for(int k = 0; k < i; ++ k){
                if(dp2[k][j - 1] && ((sum[i] - sum[k]) & ~Mask) == 0) {
                    dp2[i][j] = 1;
                    break;
                }
            }
        }
    }

    for(int i = a; i <= b; ++ i) if( dp2[n][i] ) return 1;
    return 0;

}

bool kt( LL Mask ) {
    if( a == 1 ) return ok1( Mask );
    return ok2( Mask );
}

int main() {
    //freopen(".inp","r",stdin);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++ i) {
        cin >> x;
        sum[i] = sum[i-1] + x;
    }

    LL Mask = 2199023255551LL;
    for(LL bit = 1099511627776; bit > 0 ; bit /= 2 ) {
        if( kt( Mask & ~bit ) ) {
            Mask = ( Mask & ~bit );
        }
    }

    cout << Mask;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...