Submission #846102

#TimeUsernameProblemLanguageResultExecution timeMemory
846102vjudge1Bali Sculptures (APIO15_sculpture)C++17
100 / 100
63 ms756 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define eb emplace_back
#define task ""
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
#define fi first
#define se second
#define pii pair <int, int>
#define tii tuple <int, int, int>
#define bit(mask, i) ((mask) >> (i) & 1)
using namespace std;
const int nmax = 2002;
int n, a, b;
ll pref[nmax];
bool dp[102][102];
ll sum(int i, int j)
{
    return pref[j] - pref[i - 1];
}
void sub1234()
{
    ll res = 137438953471;
    for (int k = 36; k >= 0; --k)
    {
        memset(dp, 0, sizeof dp);
        dp[0][0] = 1;
        res ^= (1LL << k);
        for (int i = 1; i <= n; ++i)
            for (int group = 1; group <= b; ++group)
                for (int j = 1; j <= i; ++j)
                    if ((sum(j, i) & res) == sum(j, i))
                        dp[i][group] |= dp[j - 1][group - 1];
        bool ok = 0;
        for (int group = a; group <= b; ++group)
            ok |= (dp[n][group]);
        if (!ok) res ^= (1LL << k);
    }
    cout << res;
}
ll dp5[nmax];
void sub5()
{
    ll res = (1LL << 41) - 1;
    for (int k = 40; k >= 0; --k)
    {
        res ^= (1LL << k);
        memset(dp5, 0x3f, sizeof dp5);
        dp5[0] = 0;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= i; ++j)
            {
                if ((sum(j, i) & res) == sum(j, i))
                    dp5[i] = min(dp5[i], dp5[j - 1] + 1);
            }
        }
        if (dp5[n] > b) res ^= (1LL << k);
    }
    cout << res;
    exit(0);
}
int main()
{
    if (ifstream(task".inp")) nx
    fast
    cin >> n >> a >> b;
    for (int y, i = 1; i <= n; ++i)
        cin >> y, pref[i] = pref[i - 1] + y;
    if (a == 1) sub5();
    sub1234();
}

Compilation message (stderr)

sculpture.cpp: In function 'int main()':
sculpture.cpp:7:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:66:31: note: in expansion of macro 'nx'
   66 |     if (ifstream(task".inp")) nx
      |                               ^~
sculpture.cpp:7:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define nx freopen (task".inp","r",stdin), freopen (task".out","w",stdout);
      |                                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:66:31: note: in expansion of macro 'nx'
   66 |     if (ifstream(task".inp")) nx
      |                               ^~
#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...