Submission #1262678

#TimeUsernameProblemLanguageResultExecution timeMemory
1262678tormentBali Sculptures (APIO15_sculpture)C++20
71 / 100
25 ms448 KiB
#include<bits/stdc++.h>
using namespace std;
// https://codeforces.com/blog/entry/17717?#comment-227370
const int N = 105;
const int LOG = 38;
int a[N];
bool dp[N][N];
bool check(long long S, int n, int A, int B){
    for(int i = 1;i <= n + 1;++i){
        for(int j = 0;j <= n;++j){
            dp[i][j] = false;
        }
    }
    for(int i = A;i <= B;++i){
        dp[n + 1][i] = true;
    }
    for(int i = n;i >= 1;--i){
        for(int j = 0;j <= n;++j){
            long long sum = 0;
            for(int ii = i;ii <= n;++ii){
                sum += a[ii];
                if((sum & S) == sum){
                    dp[i][j] = (dp[i][j] | dp[ii + 1][j + 1]);
                }
            }
        }
    }
    return dp[1][0];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, A, B;
    cin >> n >> A >> B;
    for(int i = 1;i <= n;++i){
        cin >> a[i];
    }
    long long ans = (1ll << LOG) - 1;
    for(int i = LOG - 1;i >= 0;--i){
        if(check(ans - (1ll << i), n, A, B)){
            ans -= (1ll << i);
        }
    }
    cout << ans << '\n';
}
#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...