Submission #110248

#TimeUsernameProblemLanguageResultExecution timeMemory
110248SamAndBali Sculptures (APIO15_sculpture)C++17
46 / 100
1070 ms2084 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 2003, M = 102;

int n;
int ll, rr;
int a[N];

void solv0()
{
    long long ans = (1LL << 62);
    for (int x = 0; x < (1 << n); ++x)
    {
        if ((x & (1 << 0)) == 0)
            continue;
        vector<long long> v;
        long long y = a[1];
        for (int i = 1; i < n; ++i)
        {
            if ((x & (1 << i)))
            {
                v.push_back(y);
                y = a[i + 1];
            }
            else
                y += a[i + 1];
        }
        v.push_back(y);
        long long yans = 0;
        for (int i = 0; i < v.size(); ++i)
            yans = yans | v[i];
        if (ll <= v.size() && v.size() <= rr)
            ans = min(ans, yans);
    }
    cout << ans << endl;
}

void solv1()
{
    bool dp[M][M][1 << 12] = {};
    dp[0][0][0] = true;
    for (int i = 1; i <= n; ++i)
    {
        int s = 0;
        for (int j = i; j >= 1; --j)
        {
            s += a[j];
            for (int k = 0; k <= rr; ++k)
            {
                for (int x = 0; x < (1 << 12); ++x)
                {
                    if (!dp[j - 1][k][x])
                        continue;
                    dp[i][k + 1][x | s] = true;
                }
            }
        }
    }
    int ans = (1 << 12);
    for (int k = ll; k <= rr; ++k)
    {
        for (int x = 0; x < (1 << 12); ++x)
        {
            if (dp[n][k][x])
                ans = min(ans, x);
        }
    }
    cout << ans << endl;
}

void solv2()
{
    vector<long long> dp[M][M];
    dp[0][0].push_back(0);
    for (int i = 1; i <= n; ++i)
    {
        for (int k = 0; k <= rr; ++k)
        {
            long long s = 0;
            for (int j = i; j >= 1; --j)
            {
                s += a[j];
                for (int ii = 0; ii < dp[j - 1][k].size(); ++ii)
                {
                    long long x = (dp[j - 1][k][ii] | s);
                    bool z = false;
                    for (int kk = ll; kk <= k; ++kk)
                    {
                        for (int jj = 0; jj < dp[i][kk].size(); ++jj)
                        {
                            if ((x | dp[i][kk][jj]) == x)
                            {
                                z = true;
                                break;
                            }
                        }
                        if (z)
                            break;
                    }
                    for (int jj = 0; jj < dp[i][k + 1].size(); ++jj)
                    {
                        if ((x | dp[i][k + 1][jj]) == x)
                        {
                            z = true;
                            break;
                        }
                    }
                    if (!z)
                        dp[i][k + 1].push_back(x);
                }
            }
        }
    }
    long long ans = (1LL << 62);
    for (int k = ll; k <= rr; ++k)
    {
        for (int ii = 0; ii < dp[n][k].size(); ++ii)
        {
            long long x = dp[n][k][ii];
            ans = min(ans, x);
        }
    }
    cout << ans << endl;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> ll >> rr;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    solv2();
    return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'void solv0()':
sculpture.cpp:30:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < v.size(); ++i)
                         ~~^~~~~~~~~~
sculpture.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ll <= v.size() && v.size() <= rr)
             ~~~^~~~~~~~~~~
sculpture.cpp:32:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ll <= v.size() && v.size() <= rr)
                               ~~~~~~~~~^~~~~
sculpture.cpp: In function 'void solv2()':
sculpture.cpp:83:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int ii = 0; ii < dp[j - 1][k].size(); ++ii)
                                  ~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:89:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for (int jj = 0; jj < dp[i][kk].size(); ++jj)
                                          ~~~^~~~~~~~~~~~~~~~~~
sculpture.cpp:100:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int jj = 0; jj < dp[i][k + 1].size(); ++jj)
                                      ~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:117:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ii = 0; ii < dp[n][k].size(); ++ii)
                          ~~~^~~~~~~~~~~~~~~~~
#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...