Submission #404824

#TimeUsernameProblemLanguageResultExecution timeMemory
404824tengiz05Bali Sculptures (APIO15_sculpture)C++17
50 / 100
179 ms452 KiB
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int64_t> v(n), pr(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        pr[i + 1] = pr[i] + v[i];
    }
    if (a == 1) {
        int64_t ans = 0;
        for (int bit = 50; bit >= 0; bit--) {
            vector<int> dp(n + 1, 1e9);
            dp[0] = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j < i; j++) {
                    if ((((pr[i] - pr[j]) >> bit) | ans) == ans) {
                        dp[i] = min(dp[i], dp[j] + 1);
                    }
                }
            }
            if (dp[n] > b) {
                ans ^= 1;
            }
            ans <<= 1;
        }
        ans >>= 1;
        cout << ans << '\n';
    } else {
        vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1, 1e16));
        dp[0][0] = 0;
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j < i; j++) {
                    dp[k][i] = min(dp[k][i], dp[k - 1][j] | (pr[i] - pr[j]));
                }
            }
        }
        int64_t ans = 1e16;
        for (int i = a; i <= b; i++) {
            ans = min(ans, dp[i][n]);
        }
        cout << ans << '\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...