Submission #41489

# Submission time Handle Problem Language Result Execution time Memory
41489 2018-02-17T09:42:53 Z krauch Bali Sculptures (APIO15_sculpture) C++14
37 / 100
30 ms 1676 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > PII;

#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define y1 kekek
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)

const ll ool = 1e18 + 9;
const int N = 2e3 + 6, oo = 1e9 + 9, base = 1e9 + 7;

int n, A, B, a[N], d[N][N], d2[55][22][555];
ll ans = ool;
bool bit[22];

bool check(ll mask1, ll mask2, int pos) {
    mask1 >>= 1ll * pos;
    mask2 >>= 1ll * pos;
    return ((mask1 | mask2) == mask1);
}

bool calc(ll mask, int pos) {
    d[0][0] = 1;
    forn(i, 1, n) {
        forn(j, 1, B) {
            d[i][j] = 0;
            ll sum = 0;
            for1(k, i, 1) {
                sum += a[k];
//            if (pos == 35 && i == 1 && j == 1) cerr << mask << " " << sum << " " << check(mask, sum, pos) << "\n";
                if (!check(mask, sum, pos)) continue;
                d[i][j] |= d[k - 1][j - 1];
            }
        }
    }
    forn(i, A, B) {
        if (d[n][i]) return 1;
    }
    return 0;
}

int main() {
    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n >> A >> B;
    forn(i, 1, n) {
        cin >> a[i];
    }

    if (A > 1) {
        ll ans = 0;
        for1(i, 41, 0) {
            ans |= (1ll << i);
            bool res = calc(ans, i);
            ans ^= (1ll << i);
            if (!res) ans |= (1ll << (i + 1));
        }
        if (!calc(ans, 0)) ans++;

        cout << ans << "\n";

        return 0;
    }

    forn(j, 0, 2000) d[0][j] = oo;
    d[0][0] = 0;

    forn(i, 1, n) {
        int sum = 0;
        forn(j, 0, 2000) d[i][j] = oo;
        for1(j, i, 1) {
            sum += a[j];
            forn(k, 0, 2000) {
                d[i][k | sum] = min(d[i][k | sum], d[j - 1][k] + 1);
            }
        }
    }

    int pos = 2000;
    forn(i, 0, 2000) {
        if (d[n][i] <= B) {
            pos = i;
            break;
        }
    }
    cout << pos << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 3 ms 584 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 3 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 2 ms 728 KB Output is correct
12 Correct 2 ms 816 KB Output is correct
13 Correct 2 ms 816 KB Output is correct
14 Correct 1 ms 816 KB Output is correct
15 Correct 1 ms 816 KB Output is correct
16 Correct 1 ms 816 KB Output is correct
17 Correct 2 ms 816 KB Output is correct
18 Correct 2 ms 816 KB Output is correct
19 Correct 2 ms 816 KB Output is correct
20 Correct 2 ms 816 KB Output is correct
21 Correct 2 ms 816 KB Output is correct
22 Correct 2 ms 816 KB Output is correct
23 Correct 2 ms 816 KB Output is correct
24 Correct 1 ms 816 KB Output is correct
25 Correct 2 ms 816 KB Output is correct
26 Correct 2 ms 816 KB Output is correct
27 Runtime error 2 ms 816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 816 KB Output is correct
2 Correct 2 ms 816 KB Output is correct
3 Correct 2 ms 816 KB Output is correct
4 Correct 1 ms 816 KB Output is correct
5 Correct 2 ms 816 KB Output is correct
6 Correct 2 ms 944 KB Output is correct
7 Correct 2 ms 944 KB Output is correct
8 Correct 2 ms 944 KB Output is correct
9 Correct 2 ms 944 KB Output is correct
10 Correct 2 ms 944 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 3 ms 944 KB Output is correct
13 Correct 2 ms 944 KB Output is correct
14 Correct 2 ms 944 KB Output is correct
15 Correct 1 ms 944 KB Output is correct
16 Correct 1 ms 944 KB Output is correct
17 Correct 2 ms 944 KB Output is correct
18 Correct 2 ms 944 KB Output is correct
19 Correct 2 ms 944 KB Output is correct
20 Correct 2 ms 944 KB Output is correct
21 Correct 2 ms 944 KB Output is correct
22 Correct 2 ms 944 KB Output is correct
23 Correct 2 ms 944 KB Output is correct
24 Correct 2 ms 944 KB Output is correct
25 Correct 2 ms 944 KB Output is correct
26 Correct 2 ms 944 KB Output is correct
27 Correct 2 ms 944 KB Output is correct
28 Correct 3 ms 944 KB Output is correct
29 Correct 4 ms 1072 KB Output is correct
30 Correct 5 ms 1072 KB Output is correct
31 Correct 6 ms 1200 KB Output is correct
32 Correct 6 ms 1200 KB Output is correct
33 Correct 6 ms 1200 KB Output is correct
34 Correct 6 ms 1200 KB Output is correct
35 Correct 6 ms 1200 KB Output is correct
36 Correct 6 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1308 KB Output is correct
2 Correct 2 ms 1308 KB Output is correct
3 Correct 1 ms 1308 KB Output is correct
4 Correct 1 ms 1308 KB Output is correct
5 Correct 2 ms 1308 KB Output is correct
6 Correct 2 ms 1308 KB Output is correct
7 Correct 2 ms 1308 KB Output is correct
8 Correct 2 ms 1308 KB Output is correct
9 Correct 2 ms 1308 KB Output is correct
10 Correct 2 ms 1308 KB Output is correct
11 Correct 2 ms 1308 KB Output is correct
12 Correct 2 ms 1308 KB Output is correct
13 Correct 2 ms 1308 KB Output is correct
14 Correct 2 ms 1308 KB Output is correct
15 Correct 3 ms 1308 KB Output is correct
16 Correct 4 ms 1308 KB Output is correct
17 Correct 5 ms 1308 KB Output is correct
18 Correct 7 ms 1308 KB Output is correct
19 Correct 6 ms 1308 KB Output is correct
20 Correct 10 ms 1308 KB Output is correct
21 Correct 9 ms 1328 KB Output is correct
22 Correct 6 ms 1332 KB Output is correct
23 Correct 6 ms 1332 KB Output is correct
24 Correct 6 ms 1332 KB Output is correct
25 Correct 15 ms 1332 KB Output is correct
26 Correct 12 ms 1332 KB Output is correct
27 Correct 16 ms 1496 KB Output is correct
28 Correct 19 ms 1584 KB Output is correct
29 Correct 30 ms 1584 KB Output is correct
30 Correct 18 ms 1584 KB Output is correct
31 Correct 20 ms 1584 KB Output is correct
32 Correct 19 ms 1676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1676 KB Output is correct
2 Correct 2 ms 1676 KB Output is correct
3 Correct 1 ms 1676 KB Output is correct
4 Correct 2 ms 1676 KB Output is correct
5 Correct 2 ms 1676 KB Output is correct
6 Correct 2 ms 1676 KB Output is correct
7 Correct 2 ms 1676 KB Output is correct
8 Correct 2 ms 1676 KB Output is correct
9 Correct 3 ms 1676 KB Output is correct
10 Correct 2 ms 1676 KB Output is correct
11 Correct 3 ms 1676 KB Output is correct
12 Correct 2 ms 1676 KB Output is correct
13 Correct 2 ms 1676 KB Output is correct
14 Correct 1 ms 1676 KB Output is correct
15 Correct 2 ms 1676 KB Output is correct
16 Correct 2 ms 1676 KB Output is correct
17 Correct 2 ms 1676 KB Output is correct
18 Correct 2 ms 1676 KB Output is correct
19 Correct 2 ms 1676 KB Output is correct
20 Correct 2 ms 1676 KB Output is correct
21 Correct 2 ms 1676 KB Output is correct
22 Correct 2 ms 1676 KB Output is correct
23 Correct 2 ms 1676 KB Output is correct
24 Correct 2 ms 1676 KB Output is correct
25 Correct 2 ms 1676 KB Output is correct
26 Correct 2 ms 1676 KB Output is correct
27 Runtime error 2 ms 1676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1676 KB Output is correct
2 Correct 2 ms 1676 KB Output is correct
3 Correct 1 ms 1676 KB Output is correct
4 Correct 2 ms 1676 KB Output is correct
5 Correct 2 ms 1676 KB Output is correct
6 Correct 2 ms 1676 KB Output is correct
7 Correct 2 ms 1676 KB Output is correct
8 Correct 2 ms 1676 KB Output is correct
9 Correct 2 ms 1676 KB Output is correct
10 Correct 4 ms 1676 KB Output is correct
11 Correct 2 ms 1676 KB Output is correct
12 Correct 2 ms 1676 KB Output is correct
13 Correct 2 ms 1676 KB Output is correct
14 Runtime error 3 ms 1676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -