제출 #404832

#제출 시각아이디문제언어결과실행 시간메모리
404832tengiz05Bali Sculptures (APIO15_sculpture)C++17
100 / 100
199 ms344 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];
    }
    int64_t ans = 0;
    if (a == 1) {
        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 {
        for (int bit = 50; bit >= 0; bit--) {
            vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
            dp[0][0] = 1;
            for (int k = 1; k <= n; k++) {
                for (int i = 1; i <= n; i++) {
                    for (int j = 0; j < i; j++) {
                        if ((((pr[i] - pr[j]) >> bit) | ans) == ans) {
                            dp[k][i] |= dp[k - 1][j];
                        }
                    }
                }
            }
            bool have = false;
            for (int i = a; i <= b; i++) {
                if (dp[i][n]) have = true;
            }
            if (!have) {
                ans ^= 1;
            }
            ans <<= 1;
        }
        ans >>= 1;
        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...