답안 #952615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952615 2024-03-24T11:04:54 Z Unforgettablepl Bali Sculptures (APIO15_sculpture) C++17
컴파일 오류
0 ms 0 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;

#define int long long

bool DP[101][101];
int DPmin[2001];
int arr[2001];
int a,b,n;

bool testany(int k){
    for(auto&i:DP)for(auto&j:i)j=false;
    DP[0][0]=true;
    for(int j=1;j<=b;j++){
        for(int i=j;i<=n;i++){
            int sum = arr[i];
            for(int x=i-1;x>=j-1;x--){
                if((sum|k) == k and DP[x][j-1]){DP[i][j]=true;break;}
                sum+=arr[x];
            }
        }
    }
    for(int i=a;i<=b;i++)if(DP[n][i])return true;
    return false;
}

bool test1(int k){
    for(int i=1;i<=n;i++){
        int sum = arr[i];
        DPmin[i] = 1e15;
        for(int j=i-1;j>=0;j--){
            if((sum|k)==k)DPmin[i]=min(DPmin[i],DPmin[j]+1);
            sum+=arr[j];
        }
    }
    return DPmin[n]<=b;
}

bool test(int k){
    return a==1 ? test1(k) : testany(k);
}

bool check(int x){
    bool works = test(x);
    #pragma GCC unroll 41
    #pragma GCC ivdep
    for(int bit=40;bit;bit--)if(x&(1ll<<bit))works = works or test((x^(1ll<<bit))|((1ll<<bit)-1ll));
    return works;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++)cin>>arr[i];
    int ans = -1;
    #pragma GCC unroll 42
    #pragma GCC ivdep
    for(int jump = (1ll<<41);jump;jump/=2){
        if(!check(jump+ans))ans+=jump;
    }
    cout << ans+1 << '\n';
}

Compilation message

Compilation timeout while compiling sculpture