제출 #240252

#제출 시각아이디문제언어결과실행 시간메모리
240252WhaleVomitBali Sculptures (APIO15_sculpture)C++14
100 / 100
242 ms512 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
 
#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)
 
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

const int inf = 1e9;
const int MAX_N = 2020;
int n, a, b;
ll arr[MAX_N];

bool sub(ll a, ll b) {
    return (a | b) == b;
}

bool poss(ll msk) {
    if(a == 1) {
        vi dp(n);
        M00(i, n) dp[i] = inf;
        if(sub(arr[0], msk)) dp[0] = 1;
        MOO(i, 1, n) {
            ll cur = arr[i];
            if(sub(cur,msk) && dp[i-1] != -1) dp[i] = dp[i-1] + 1;
            M00d(j, i) {
                cur += arr[j];
                if(sub(cur,msk) && (j == 0 || dp[j-1] != inf)) {
                    dp[i] = min(dp[i], (j == 0 ? 1 : dp[j-1] + 1));
                }
            }
        }
        return dp[n-1] != -1 && dp[n-1] <= b;
    } else {
        vector<vector<bool>> dp(n);
        M00(i, n) dp[i].resize(n+1);
        ll cur = 0;
        M00(i, n) {
            cur += arr[i];
            if(sub(cur,msk)) dp[i][1] = 1;
        }
        MOO(i, 1, n) {
            MOO(j, 2, n+1) {
                ll cur = arr[i];
                if(sub(cur,msk) && dp[i-1][j-1]) dp[i][j] = 1;
                MOOd(k, 1, i) {
                    cur += arr[k];
                    if(sub(cur,msk) && dp[k-1][j-1]) dp[i][j] = 1;
                }
            }
        }
        MOO(i, a, b+1) if(dp[n-1][i]) return 1;
        return 0;
    }
}

int main() { FAST
    cin >> n >> a >> b;
    M00(i, n) cin >> arr[i];
    ll x = (1LL<<62)-1LL;
    M00d(i, 62) {
        bitset<62> bs(x);
        if(poss(x ^ (1LL<<i))) {
            x ^= (1LL<<i);
        }
    }
    finish(x);
}

#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...