제출 #1357759

#제출 시각아이디문제언어결과실행 시간메모리
1357759AgageldiBali Sculptures (APIO15_sculpture)C++17
9 / 100
1096 ms464 KiB
#include <bits/stdc++.h>
using namespace std;

#define N 500005
#define ll long long

const int inf = INT_MAX;
const int M = 998244353;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n, a[N], B, A, b[N], ans = -1;
void solve(int x) {
    if(x == n) {
        ll cnt = 0, sm = 0, vl = 0;
        for(int i = 1; i <= n; i++) {
            sm += a[i];
            if(b[i]) {
                vl |= sm;
                sm = 0;
                cnt++;
            }
        }
        if(cnt > B || cnt < A) return;
        if(ans == -1) ans = vl;
        ans = min(ans, vl);
        return;
    }
    b[x] = 1;
    solve(x + 1);
    b[x] = 0;
    solve(x + 1);
}

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    b[n] = 1;
    solve(1);
    cout << ans << '\n';
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…