제출 #211772

#제출 시각아이디문제언어결과실행 시간메모리
211772DS007Bali Sculptures (APIO15_sculpture)C++14
100 / 100
172 ms512 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2005;
int n, a, b;
int y[N], p[N];

void solveTestCase() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> y[i];

    p[0] = y[0];
    for (int i = 1; i < n; i++)
        p[i] = y[i] + p[i - 1];

    if (n > 100) {
        int ans = 0;
        for (int i = 45; i >= 0; i--) {
            int dp[n];
            fill(dp, dp + n, 1e14);
            int up = ans + (1ll << i);
            bool check = y[0] < up;
            if ((y[0] & (1ll << i)) == 0)
                dp[0] = 1;

            for (int j = 1; j < n; j++) {
                check = check && y[j] < up;
                if (p[j] < up && (p[j] | up) < up + (1ll << i) && (p[j] & (1ll << i)) == 0)
                    dp[j] = 1;

                for (int k = j - 1; k >= 0; k--) {
                    if ((p[j] - p[k + 1] + y[k + 1]) < up && ((p[j] - p[k + 1] + y[k + 1]) | up) < up + (1ll << i) &&
                        ((p[j] - p[k + 1] + y[k + 1]) & (1ll << i)) == 0)
                        dp[j] = min(dp[j], dp[k] + 1);
                }
            }

            if (!check || dp[n - 1] > b)
                ans = up;
        }

        cout << ans;
    } else {
        int ans = 0;
        for (int i = 45; i >= 0; i--) {
            bool dp[n + 1][n];
            memset(dp, 0, sizeof(dp));

            int up = ans + (1ll << i);
            bool check = y[0] < up;
            for (int j = 1; j < n; j++)
                check = check && y[j] < up;

            for (int j = 0; j < n; j++) {
                if (p[j] < up && (p[j] | up) < up + (1ll << i) && (p[j] & (1ll << i)) == 0)
                   dp[1][j] = true;
            }

            for (int j = 2; j <= n; j++) {
                for (int k = j - 1; k < n; k++) {
                    for (int l = k - 1; l >= 0; l--) {
                        if ((p[k] - p[l + 1] + y[l + 1]) < up && ((p[k] - p[l + 1] + y[l + 1]) | up) < up + (1ll << i) && ((p[k] - p[l + 1] + y[l + 1]) & (1ll << i)) == 0)
                            dp[j][k] = dp[j][k] || dp[j - 1][l];
                    }
                }
            }

            bool flag = false;
            for (int j = a; j <= b; j++) {
                if (dp[j][n - 1])
                    flag = true;
            }

            if (!check || !flag)
                ans = up;
        }

        cout << ans;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    //cin >> test;
    while (test--)
        solveTestCase();
}
#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...