제출 #1321254

#제출 시각아이디문제언어결과실행 시간메모리
1321254AMel0nBali Sculptures (APIO15_sculpture)C++20
37 / 100
12 ms428 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll N, A, B;
vector<ll> V;
vector<ll> PS;
ll sum(ll a, ll b) {
    return PS[b+1] - PS[a];
}
bool check(ll x, ll y) {
    vector<vector<bool>> dp(N+1, vector<bool>(B+1)); // dp[i][# of partitions]
    dp[0][0] = true;
    for(ll i = 0; i <= N; i++) {
        for(ll j = 0; j < i; j++) {
            for(ll k = 1; k <= B; k++) {
                dp[i][k] = dp[i][k] | (dp[j][k-1] & ((sum(j, i-1) & x) == 0) & !(sum(j, i-1) & (1 << y)));
                // cout << i << ' ' << j << ' ' << k << ' ' << dp[j][k-1] << ' ' << sum(j, i-1) << ' ' << !(sum(j, i-1) & (1 << y)) << ' ' << x << ' ' << y << ' ' << dp[i][k] << endl;
            }
        }
    }
    for(ll k = A; k <= B; k++) {
        if (dp[N][k]) return dp[N][k];
    }
    return false;
}
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    V.resize(N), PS.resize(N+1);
    ll UB = 0;
    for(ll i = 0; i < N; i++) {
        cin >> V[i];
        PS[i+1] = PS[i] + V[i];
        UB += V[i];
    }
    UB = __lg(UB);
    // ll cur = (1 << UB+1) - 1;
    ll bru = 0;
    ll cur = 0;
    for(ll k = UB; k >= 0; k--) {
        if (!check(bru, k)) cur ^= (1 << k);
        else bru ^= (1 << k);
        // cout << k << ' ' << cur << endl;
    }
    cout << cur << 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...