Submission #634682

#TimeUsernameProblemLanguageResultExecution timeMemory
634682tvladm2009Bali Sculptures (APIO15_sculpture)C++14
71 / 100
1081 ms1776 KiB
#include <iostream>
#include <string.h>
#define int long long

using namespace std;

const int MAX_N = 2000;
int a[MAX_N + 1];
bool sepoate[MAX_N + 1][MAX_N + 1];
int n, xmin, xmax;

bool check(int mask, int pos) {
    memset(sepoate[0], false, sizeof(sepoate[0]));
    sepoate[0][0] = true;
    for (int i = 1; i <= n; i++) {
        sepoate[i][0] = false;
        for (int x = 1; x <= xmax; x++) {
            sepoate[i][x] = false;
            int sum = 0;
            for (int j = i; j >= 1; j--) {
                sum += a[j];
                if ((sum & ~mask) >= (1LL << pos)) {
                    continue;
                }
                if (sepoate[j - 1][x - 1] == true) {
                    sepoate[i][x] = true;
                    break;
                }
            }
        }
    }
    bool ok = false;
    for (int i = xmin; i <= xmax; i++) {
        ok |= sepoate[n][i];
    }
    return ok;
}

signed main() {
    cin >> n >> xmin >> xmax;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int answer = 0;
    for (int bit = 50; bit >= 0; bit--) {
        if (check(answer, bit) == false) {
            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...