Submission #1357465

#TimeUsernameProblemLanguageResultExecution timeMemory
1357465Desh03Bali Sculptures (APIO15_sculpture)C++20
71 / 100
1047 ms508 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> p(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        p[i] += p[i - 1];
    }
    long long ans = (1LL << 45) - 1;
    for (int i = 44; i >= 0; i--) {
        ans ^= (1LL << i);
        vector dp(n + 1, vector<bool> (n + 1));
        dp[0][0] = 1;
        for (int j = 1; j <= n; j++) {
            for (int t = 1; t <= j; t++) {
                for (int k = 0; k < j; k++) {
                    if (((p[j] - p[k]) & ans) == p[j] - p[k] && dp[k][t - 1]) {
                        dp[j][t] = 1;
                        break;
                    }
                }
            }
        }
        bool ok = 0;
        for (int j = a; j <= b; j++) {
            if (dp[n][j]) {
                ok = 1;
                break;
            }
        }
        if (!ok) {
            ans ^= (1LL << i);
        }
    }
    cout << ans << '\n';
    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...