제출 #163376

#제출 시각아이디문제언어결과실행 시간메모리
163376combi1k1Bali Sculptures (APIO15_sculpture)C++14
50 / 100
165 ms504 KiB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long

const int   N   = 2e3 + 1;

bool f[N][N];

ll  a[N];
int g[N];

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

    int n;  cin >> n;
    int A;  cin >> A;
    int B;  cin >> B;

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

    ll  cur_mask = 0;

    if (A > 1)  {
        f[0][0] = 1;

        for(int b = 40 ; b >= 0 ; --b)  {
            for(int i = 1 ; i <= n ; ++i)
            for(int j = 1 ; j <= n ; ++j)   {
                f[i][j] = 0;
                for(int k = 0 ; k < i ; ++k)    {
                    ll  S = a[i] - a[k];

                    S >>= b;
                    S <<= b;

                    if((S & cur_mask) != S)
                        f[i][j] |= f[k][j - 1];
                }
            }
            bool ch = 0;

            for(int i = A ; i <= B ; ++i)
                ch |= f[n][i];

            if(!ch) cur_mask |= (1ll << b);
        }
    }
    else    {
        for(int b = 40 ; b >= 0 ; --b)  {
            for(int i = 1 ; i <= n ; ++i)   {
                g[i] = 1e9;
                for(int j = 0 ; j < i ; ++j)    {
                    ll  S = a[i] - a[j];

                    S >>= b;
                    S <<= b;

                    if ((S & cur_mask) != S)
                        continue;

                    g[i] = min(g[i],g[j] + 1);
                }
            }
            if (g[n] > B)   cur_mask |= (1ll << b);
        }
    }

    cout << cur_mask << endl;
}
#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...