Submission #719700

#TimeUsernameProblemLanguageResultExecution timeMemory
719700joelgun14Bali Sculptures (APIO15_sculpture)C++17
21 / 100
1 ms340 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int y[n + 1];
    ll pref[n + 1];
    pref[0] = 0;
    for(int i = 1; i <= n; ++i)
        cin >> y[i], pref[i] = pref[i - 1] + y[i];;
    // a = 1 -> size only from 1...b
    // else -> brute force every size
    int notchosen = 0, chosen = 0;
    for(int i = 29; i >= 0; --i) {
        // create partition where sum of everything does not have ith bit on and still conforms to previous selected
        // try create partition without 1 << i, in
        int dp[n + 1];
        fill(dp, dp + n + 1, 1e9);
        dp[0] = 0;
        for(int j = 1; j <= n; ++j) {
            for(int k = 1; k <= j; ++k) {
                if(!((pref[j] - pref[k - 1]) & (notchosen | (1 << i)))) {
                    dp[j] = min(dp[j], dp[k - 1] + 1);
                }
            }
        }
        if(dp[n] <= b)
            notchosen += 1 << i;
        else
            chosen += 1 << i;
    }
    cout << chosen << 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...