제출 #390060

#제출 시각아이디문제언어결과실행 시간메모리
390060thuanqvbn03Bali Sculptures (APIO15_sculpture)C++17
50 / 100
111 ms464 KiB
//Flower_On_Stone
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2005;

int n, a, b;
long long arr[MAX_N], prefixSum[MAX_N];
int dp[MAX_N];

bool check(long long pattern, long long cast)
{
    long long x = pattern;
    for (int i = 0; i < 50; i++)
    {
        if (!((cast >> i) & 1))
        {
            x |= (1LL << i);
        }
        else
        {
            break;
        }
    }
    memset(dp, 0x3f, sizeof(int) * (n + 1));
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            long long sum = prefixSum[i] - prefixSum[i - j];
            if (sum <= x && ((sum & cast) & pattern) == (sum & cast))
            {
                dp[i] = min(dp[i], dp[i - j] + 1);
            }
        }
    }
    return dp[n] <= b;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        prefixSum[i] = prefixSum[i - 1] + arr[i];
    }
    int maxPos = 0;
    for (int i = 1; i < 50; i++)
    {
        if ((prefixSum[n] >> i) & 1)
        {
            maxPos = i;
        }
    }
    long long answer = 0, cast = 0;
    for (int i = maxPos; i >= 0; i--)
    {
        cast |= (1LL << i);
        if (!check(answer, cast))
        {
            answer |= (1LL << i);
        }
    }
    cout << answer;
    return 0;
}
#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...