Submission #613867

#TimeUsernameProblemLanguageResultExecution timeMemory
613867DeMen100nsBali Sculptures (APIO15_sculpture)C++17
100 / 100
572 ms32240 KiB
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/

#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e3 + 5;
const long long INF = numeric_limits<long long>::max() / 2;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;

int sum[N][N], A[N], ans = 0, rans = 0, n, a, b;

bool check(int a, int b, int p){
    return ((a & b) >> p) == 0;
}

void solve4(){
    int dp[N][N];
    
    for(int bit = 42; bit >= 0; --bit){
        ans ^= (1LL << bit);

        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= n; ++j){
                dp[i][j] = INF;
            }
        }
        for(int i = 1; i <= n; ++i){
            if (check(ans, sum[1][i], bit)) dp[1][i] = sum[1][i];
        }

        int mi = INF;
        if (a == 1) mi = dp[1][n];

        for(int tme = 2; tme <= b; ++tme){
            for(int i = tme; i <= n; ++i){
                for(int j = tme; j <= i; ++j){
                    if (check(ans, sum[j][i], bit)){
                        dp[tme][i] = min(dp[tme][i], dp[tme - 1][j - 1] | sum[j][i]);
                    }
                }
            }
            if (tme >= a) mi = min(mi, dp[tme][n]);
        }

        if (mi == INF){
            ans ^= (1LL << bit);
            rans ^= (1LL << bit);
        }
    }

    cout << rans;
}

void solve5(){
    int dp[N];
    
    for(int bit = 42; bit >= 0; --bit){
        ans ^= (1LL << bit);

        for(int i = 1; i <= n; ++i) dp[i] = INF;
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= i; ++j){
                if (check(ans, sum[j][i], bit)) dp[i] = min(dp[i], dp[j - 1] + 1);
            }
        }

        if (dp[n] > b){
            ans ^= (1LL << bit);
            rans ^= (1LL << bit);
        }
    }

    cout << rans;
}

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

    if (a == 1){
        solve5();
    } else {
        solve4();
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("codeforces.inp","r",stdin);
    // freopen("codeforces.out","w",stdout);

    int t = 1; //cin >> t;
    while (t--)
    {
        solve();
    }
}
#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...