Submission #392611

#TimeUsernameProblemLanguageResultExecution timeMemory
392611giorgikobBali Sculptures (APIO15_sculpture)C++14
100 / 100
142 ms452 KiB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 2e5+5, mod = 1e9+7, sq = 500;

int n,a,b;
ll A[N];
ll answer = 0;
ll dp[N];

inline void test_case(){

    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        cin >> A[i];
    }

    if(a == 1){
        answer = (1LL<<61) - 1;
        for(int bit = 60; bit >= 0; bit--){
            answer ^= (1LL<<bit);
            //cout << x << endl;
            for(int i = 0; i <= n; i++) dp[i] = 1e9;
            dp[0] = 0;
            for(int i = 0; i <= n; i++){
                //cout << dp[i] << " ";
                if(dp[i] == 1e9) continue;
                ll sum = 0;
                for(int j = i+1; j <= n; j++){
                    sum += A[j];
                    if((sum | answer) == answer){
                        dp[j] = min(dp[j],dp[i]+1);
                    }
                }
            }

            //cout << endl;

            if(dp[n] > b){
                answer |= (1LL<<bit);
            }
        }
    } else {
        bool dp[n+5][n+5];
        answer = (1LL<<61) - 1;
        for(int bit = 60; bit >= 0; bit--){
            answer ^= (1LL<<bit);
            for(int i = 0; i <= n; i++)
                for(int j = 0; j <= n+1; j++)
                    dp[i][j] = 0;
            dp[0][0] = 1;
            for(int i = 0; i <= n; i++){
                for(int j = 0; j <= n; j++){
                    if(dp[i][j] == 0) continue;
                    ll sum = 0;
                    for(int t = i+1; t <= n; t++){
                        sum += A[t];
                        if((sum | answer) == answer){
                            dp[t][j+1] |= 1;
                        }
                    }
                }
            }

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

            if(!ok){
                answer |= (1LL<<bit);
            }
        }
    }

    cout << answer << endl;
}

 main(){
    ios::sync_with_stdio(0);

    int T = 1;
    //cin >> T;
    while(T--){
        test_case();
    }
}

Compilation message (stderr)

sculpture.cpp:83:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   83 |  main(){
      |       ^
#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...