Submission #160170

#TimeUsernameProblemLanguageResultExecution timeMemory
160170BlueDiamondBali Sculptures (APIO15_sculpture)C++14
71 / 100
9 ms888 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 2000 + 7;
int n, mn, mx;
ll a[N];
bool good[N][N], ok[N][N];

bool okapi(ll x, ll cur, int bit) {
        x -= x & cur;
        return (x < (1LL << bit));
}

bool valid(ll cur, int bit) {
        ll val = (1LL << bit);

        for (int i = 1; i <= n; i++) {
                ll sum = 0;
                for (int j = i; j <= n; j++) {
                        sum += a[j];
                        good[i][j] = okapi(sum, cur, bit);
                }
        }

        for (int i = 0; i <= n; i++)
                for (int j = 0; j <= mx; j++)
                        ok[i][j] = 0;

        ok[0][0] = 1;
        for (int i = 0; i < n; i++)
                for (int c = 0; c < mx; c++)
                        if (ok[i][c])
                                for (int j = i + 1; j <= n; j++)
                                        if (good[i + 1][j])
                                                ok[j][c + 1] = 1;

        for (int c = mn; c <= mx; c++)
                if (ok[n][c])
                        return 1;
        return 0;
}

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

   ///     freopen ("input", "r", stdin);

        cin >> n >> mn >> mx;
        for (int i = 1; i <= n; i++)
                cin >> a[i];

        if (n <= 100) {
                ll sum = 0;
                for (int i = 1; i <= n; i++)
                        sum += a[i];

                ll mask = 0;
                for (int k = log2(sum); k >= 0; k--)
                        if (valid(mask, k) == 0)
                                mask += (1LL << k);

                cout << mask << "\n";
                return 0;
        }

        return 0;
}

Compilation message (stderr)

sculpture.cpp: In function 'bool valid(ll, int)':
sculpture.cpp:17:12: warning: unused variable 'val' [-Wunused-variable]
         ll val = (1LL << bit);
            ^~~
#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...