제출 #719703

#제출 시각아이디문제언어결과실행 시간메모리
719703joelgun14Bali Sculptures (APIO15_sculpture)C++17
50 / 100
270 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
        ll notchosen = 0, chosen = 0;
        for(int i = 63; 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 | (1ll << i)))) {
                        dp[j] = min(dp[j], dp[k - 1] + 1);
                    }
                }
            }
            if(dp[n] <= b)
                notchosen += 1ll << i;
            else
                chosen += 1ll << 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...