제출 #370255

#제출 시각아이디문제언어결과실행 시간메모리
370255BartolMBali Sculptures (APIO15_sculpture)C++17
100 / 100
152 ms748 KiB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int LOG=45;
const int N=2005;

int n, A, B;
ll pref[N];
int dp[N][N];
int dp2[N];

int f(ll mask) {
    dp[0][0]=1;
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=i; ++j) {
            dp[i][j]=0;
            for (int k=0; k<i; ++k) {
                if ((mask | (pref[i]-pref[k]))!=mask) continue;
                dp[i][j]|=dp[k][j-1];
            }
        }
    }
    for (int i=A; i<=B; ++i) if (dp[n][i]) return 1;
    return 0;
}

int f2(ll mask) {
    dp2[0]=0;
    for (int i=1; i<=n; ++i) {
        dp2[i]=INF;
        for (int j=0; j<i; ++j) {
            if ((mask | (pref[i]-pref[j]))!=mask) continue;
            dp2[i]=min(dp2[i], dp2[j]+1);
        }
    }
    return dp2[n]<=B;
}

void solve() {
    ll sol=(1LL<<(LOG+1))-1;
    for (int i=LOG; i>=0; --i) {
        ll curr=(1LL<<i);
        if (A==1) {
            if (f2(sol^curr)) sol^=curr;
            continue;
        }
        if (f(sol^curr)) sol^=curr;
    }
    printf("%lld\n", sol);
}

void load() {
    scanf("%d %d %d", &n, &A, &B);
    for (int i=1; i<=n; ++i) {
        scanf("%lld", &pref[i]);
        pref[i]+=pref[i-1];
    }
}

int main() {
    load();
    solve();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sculpture.cpp: In function 'void load()':
sculpture.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |     scanf("%d %d %d", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |         scanf("%lld", &pref[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
#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...