Submission #568548

#TimeUsernameProblemLanguageResultExecution timeMemory
568548Ooops_sorryBali Sculptures (APIO15_sculpture)C++14
100 / 100
110 ms360 KiB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld double
#define ll long long

mt19937 rnd(51);

const int K = 42;

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll res = (1LL << K) - 1;
    for (int b = K - 1; b >= 0; b--) {
        res -= (1LL << b);
        if (n <= 100) {
            vector<vector<bool>> dp(n + 1, vector<bool>(n + 1));
            dp[0][0] = 1;
            for (int i = 0; i < n; i++) {
                ll sum = 0;
                for (int j = i; j < n; j++) {
                    sum += a[j];
                    if ((sum | res) == res) {
                        for (int f = 0; f < n; f++) {
                            if (dp[i][f]) {
                                dp[j + 1][f + 1] = 1;
                            }
                        }
                    }
                }
            }
            bool good = 0;
            for (int i = x; i <= y; i++) {
                if (dp[n][i]) {
                    good = 1;
                }
            }
            if (!good) res += (1LL << b);
        } else {
            vector<int> mn(n + 1, n + 1);
            mn[0] = 0;
            for (int i = 0; i < n; i++) {
                ll sum = 0;
                for (int j = i; j < n; j++) {
                    sum += a[j];
                    if ((sum | res) == res) {
                        mn[j + 1] = min(mn[j + 1], mn[i] + 1);
                    }
                }
            }
            if (mn[n] > y) {
                res += (1LL << b);
            }
        }
    }
    cout << res << endl;
    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...