Submission #839343

#TimeUsernameProblemLanguageResultExecution timeMemory
839343popovicirobertBali Sculptures (APIO15_sculpture)C++14
100 / 100
153 ms464 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef HOME
    ifstream cin("input.in");
    ofstream cout("output.out");
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, A, B;
    cin >> n >> A >> B;

    vector<int> x(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }

    long long answer = 0;

    if (n <= 100) {

        for (int bit = 50; bit >= 0; bit--) {

            vector<vector<bool>> dp(B + 1, vector<bool>(n + 1));    
            dp[0][0] = true;

            for (int i = 1; i <= B; i++) {
                for (int j = 1; j <= n; j++) {
                    long long sum = 0;
                    for (int k = j - 1; k >= 0; k--) {
                        sum += x[k + 1];
                        if (((sum | answer) >> bit) == (answer >> bit)) {
                            dp[i][j] = (dp[i][j] | dp[i - 1][k]);
                        }
                    }
                }
            }

            bool good = false;
            for (int i = A; i <= B; i++) {
                good |= dp[i][n];
            }

            if (!good) {
                answer += (1LL << bit);
            }
        }
    } else {
        for (int bit = 50; bit >= 0; bit--) {

            vector<int> dp_min(n + 1, n + 1);
            dp_min[0] = 0;
            
            for (int j = 1; j <= n; j++) {
                long long sum = 0;
                for (int k = j - 1; k >= 0; k--) {
                    sum += x[k + 1];
                    if (((sum | answer) >> bit) == (answer >> bit)) {
                        dp_min[j] = min(dp_min[j], dp_min[k] + 1);
                    }
                }
            }
            
            if (dp_min[n] > B) {
                answer += (1LL << bit);
            }
        }
    }

    cout << answer;

    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...