Submission #1016173

#TimeUsernameProblemLanguageResultExecution timeMemory
1016173andrei_iorgulescuBali Sculptures (APIO15_sculpture)C++14
100 / 100
201 ms23388 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int inf = 1e18;

int n,a,b,v[2005];
int s[2005][2005];
bool dp[105][105];
int d[2005];

bool pot(int x)
{
    if (a != 1)
    {
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++)
                dp[i][j] = false;
        dp[0][0] = true;
        for (int j = 1; j <= n; j++)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int q = 1; q <= i; q++)
                    if ((s[q][i] & x) == 0 and dp[j - 1][q - 1])
                        dp[j][i] = true;
            }
        }
        for (int i = a; i <= b; i++)
            if (dp[i][n] == true)
                return true;
        return false;
    }
    else
    {
        for (int i = 0; i <= 2000; i++)
            d[i] = inf;
        d[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int q = 1; q <= i; q++)
            {
                if ((s[q][i] & x) == 0)
                    d[i] = min(d[i],1 + d[q - 1]);
            }
        }
        if (d[n] <= b)
            return true;
        return false;
    }
}

signed main()
{
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    for (int i = 1; i <= n; i++)
    {
        s[i][i] = v[i];
        for (int j = i + 1; j <= n; j++)
            s[i][j] = s[i][j - 1] + v[j];
    }
    int ans = 0;
    for (int bit = 50; bit >= 0; bit--)
    {
        int chk = ans + (1ll << bit);
        if (pot(chk))
            ans = chk;
    }
    cout << (1ll << 51) - 1 - ans;
    return 0;
}

/*
6 1 3
8 1 2 1 5 4
*/

/**
Idee: incerc sa imi construiesc raspunsul bit cu bit, la un pas am deja dintr-un prefix de biti unii pe care sigur nu ii iau
Deci voi face log verificari de tipul: pot sa impart sirul in [A B] intervale, suma fiecaruia sa dea and-ul cu x = 0?

Daca A != 1 -> Fac in n^3 o dinamica gen: dp[j][i] = pot sa impart primele i in j grupe sa respecte conditia?
dp[j][i] vine din dp[j - 1][q < i] a.i (sum(q + 1...i) & x) == 0

Daca A == 1 -> Fac in n^2 o dinamica gen: dp[i] = -1 daca nu pot imparti primele i in grupe sa dea and-ul 0 cu x, sau nr minim de grupe altfel
dp[i] vine din dp[j < i] a.i (sum(q + 1...i) & x) == 0, practic o sa fie -1 daca nu vine din niciuna >= 0 sau 1 + aia minima altfel
**/
#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...