Submission #1292982

#TimeUsernameProblemLanguageResultExecution timeMemory
1292982dm10r7Bali Sculptures (APIO15_sculpture)C++20
100 / 100
578 ms948 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2010;

bitset<N> dp[N];
long long pref[N];
long long a[N];

int main() {
    int n, l, r;
    scanf("%d %d %d", &n, &l, &r);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        pref[i] = pref[i - 1] + a[i];
    }
    long long ans = (1LL << 45) - 1;
    for(long long bit = 1LL << 44; bit; bit >>= 1) {
        ans ^= bit;
        for(int i = 0; i <= n; i++) dp[i].reset();
        dp[0][0] = 1;
        for(int i = 0; i < n; i++) {
            if(dp[i].none()) continue;
            long long sum = pref[i];
            for(int j = i + 1; j <= n; j++) {
                long long val = pref[j] - sum;
                if(val > ans) break;
                if((val & ans) == val) {
                    dp[j] |= (dp[i] << 1);
                }
            }
        }
        bool ok = 0;
        for(int cnt = l; cnt <= r; cnt++) {
            if(dp[n][cnt]) { ok = 1; break; }
        }
        if(!ok) ans |= bit;
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d %d", &n, &l, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld", &a[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...