Submission #389993

# Submission time Handle Problem Language Result Execution time Memory
389993 2021-04-15T04:02:05 Z thuanqvbn03 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 332 KB
//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];
bool 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, false, sizeof(bool) * (n + 1));
    dp[0] = true;
    for (int i = 1; i <= n; i++)
    {
        for (int j = a, lim = min(b, i); j <= lim; j++)
        {
            if (dp[i - j])
            {
                long long sum = prefixSum[i] - prefixSum[i - j];
                if (sum <= x && ((sum & cast) & pattern) == (sum & cast))
                {
                    dp[i] = true;
                    break;
                }
            }
        }
    }
    return dp[n];
}
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 time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -