Submission #499387

#TimeUsernameProblemLanguageResultExecution timeMemory
499387StickfishBali Sculptures (APIO15_sculpture)C++17
100 / 100
242 ms336 KiB
#include <iostream>
#include <bitset>
using namespace std;
using ll = long long;

const int MAXN = 2077;
ll a[MAXN];
ll minsg_[MAXN]; 
ll* minsg = minsg_ + 1;
bitset<MAXN> possg_[MAXN];
bitset<MAXN>* possg = possg_ + 1;

signed main() {
    int n, A, B;
    cin >> n >> A >> B;
    for (int i = 0; i < n; ++i) 
        cin >> a[i];
    ll ans = 0;
    for (ll bt = 61; bt >= 0; --bt) {
        for (int i = 0; i < n; ++i) {
            if (A == 1)
                minsg[i] = MAXN;
            else
                possg[i] = 0;
        }
        possg[-1][0] = 1;
        for (int i = 0; i < n; ++i) {
            ll sm = 0;
            for (int j = i; j >= 0; --j) {
                sm += a[j];
                if ((sm - (sm & ans)) < (1ll << bt)) {
                    if (A == 1) {
                        minsg[i] = min(minsg[i], minsg[j - 1] + 1);
                    } else {
                        possg[i] |= possg[j - 1] << 1;
                    }
                }
            }
        }
        if (A == 1) {
            if (minsg[n - 1] > B) {
                ans |= (1ll << bt);
            }
        } else {
            bool isok = false;
            for (int t = A; t <= B && !isok; ++t) {
                if (possg[n - 1][t])
                    isok = true;
            }
            if (!isok) {
                ans |= (1ll << bt);
            }
        }
    }
    cout << ans << endl;
}
#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...