Submission #207635

#TimeUsernameProblemLanguageResultExecution timeMemory
207635DystoriaXBali Sculptures (APIO15_sculpture)C++14
71 / 100
1081 ms888 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
int n, a, b;
int y[100010];
bool dp[1010][1010];
long long pref[1010], mx;
const int lgmx = 37;

long long lsb(long long x){
    return x & (-x);
}

bool check(){
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            dp[i][j] = false;
 
    dp[0][0] = true;
 
    for(int j = 1; j <= n; j++){
        for(int i = j; i <= n; i++){
            for(int k = j - 1; k < i; k++){
                long long sum = pref[i] - pref[k];

                if(lsb(mx & sum) != lsb(mx) && (sum & (~mx)) <= lsb(mx)){
                    dp[i][j] |= dp[k][j - 1];
                }
            }
        }
    }

    bool ret = false;

    for(int i = a; i <= b; i++){
        ret |= dp[n][i];
    }

    return ret;
}
 
int main(){
    // freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &a, &b);
 
    for(int i = 1; i <= n; i++){
        scanf("%d", &y[i]);
        pref[i] = y[i] + pref[i - 1];
    }

    for(int i = lgmx; i >= 0; i--){
        long long tmp = mx;

        mx |= (1LL << i);

        if(check()) mx = tmp;
    }
 
    printf("%lld\n", mx);
    
    return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:46: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:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &y[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...