제출 #554707

#제출 시각아이디문제언어결과실행 시간메모리
554707alextodoranBali Sculptures (APIO15_sculpture)C++17
71 / 100
23 ms468 KiB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100;
const int BITS = 41;

int N, Xmin, Xmax;
int V[N_MAX + 2];

bool dp[N_MAX + 2][N_MAX + 2];

bool makePref (ll pref, int suffLen) {
    fill(dp[0] + 1, dp[0] + Xmax + 1, false);
    dp[0][0] = true;
    for (int i = 1; i <= N; i++) {
        dp[i][0] = false;
        for (int x = 1; x <= Xmax; x++) {
            dp[i][x] = false;
            ll sum = 0;
            for (int j = i; j >= 1; j--) {
                sum += V[j];
                if ((sum & ~pref) >= ((ll) 1 << suffLen)) {
                    continue;
                }
                if (dp[j - 1][x - 1] == true) {
                    dp[i][x] = true;
                    break;
                }
            }
        }
    }
    for (int x = Xmin; x <= Xmax; x++) {
        if (dp[N][x] == true) {
            return true;
        }
    }
    return false;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> Xmin >> Xmax;
    for (int i = 1; i <= N; i++) {
        cin >> V[i];
    }
    ll answer = 0;
    for (int bit = BITS - 1; bit >= 0; bit--) {
        if (makePref(answer, bit) == false) {
            answer |= ((ll) 1 << bit);
        }
    }
    cout << answer << "\n";

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