Submission #109830

#TimeUsernameProblemLanguageResultExecution timeMemory
109830PeppaPigBali Sculptures (APIO15_sculpture)C++14
21 / 100
1080 ms4332 KiB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 2e3+5;

int n, A, B;
long pref[N];
bool C[N][N];

bool chk(long mid) {
    if(A == 1) {
        long ans = 0;
        for(int bit = 62; ~bit; bit--) {
            int dp[N]; fill_n(dp, N, 1e9);
            dp[0] = 0;
            for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) {
                long sum = pref[j] - pref[i-1];
                if(!(sum >> bit & 1) && ((sum | ans) >> (bit + 1)) == (ans >> (bit + 1)))
                    dp[j] = min(dp[j], dp[i-1] + 1);
            }
            if(dp[n] > B) ans |= (1ll << bit);
        }
        return (ans <= mid);
    } else {
        memset(C, 0, sizeof C);
        C[0][0] = true;
        for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = i; j <= n; j++) {
            long sum = pref[j] - pref[i-1];
            if((sum & mid) == sum) C[j][k] |= C[i-1][k-1]; 
        }
        for(int i = 1; i <= n; i++) for(int j = A; j <= B; j++) if(C[i][j]) return true;
        return false;
    }
}

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

    long l = 0, r = 1e18;
    while(l < r) {
        long mid = (l + r) >> 1;
        if(chk(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%lld\n", r);

    return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:41:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%lld", pref+i), pref[i] += pref[i-1];
                                 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...