Submission #482735

# Submission time Handle Problem Language Result Execution time Memory
482735 2021-10-26T07:26:52 Z jalsol Bali Sculptures (APIO15_sculpture) C++17
100 / 100
98 ms 4176 KB
#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif

using namespace std;

const bool __initialization = []() {
    cin.tie(nullptr)->sync_with_stdio(false);
#define TASK "empty"
    if (fopen(TASK".inp", "r")) {
        (void)(!freopen(TASK".inp", "r", stdin));
        (void)(!freopen(TASK".out", "w", stdout)); }
    cout << setprecision(12) << fixed;
    return true;
}();

using ll = long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)

template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }

constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxn = 2000 + 5;

int n, lo, hi;
int a[maxn];
ll pref[maxn];

struct Sub4 {
    ll ans = (1LL << 41) - 1;
    bool dp[maxn][maxn];

    bool check(ll x) {
        dp[0][0] = true;

        For (i, 1, n) {
            For (j, 1, min(i, hi)) {
                dp[i][j] = false;

                Ford (k, i - 1, 0) {
                    if (((pref[i] - pref[k]) | x) <= x && dp[k][j - 1]) {
                        dp[i][j] = true;
                        break;
                    }
                }
            }
        }

        For (i, lo, hi) {
            if (dp[n][i]) return true;
        }

        return false;
    }

    void solve() {
        Repd (i, 41) {
            if (check(ans ^ (1LL << i))) {
                ans ^= (1LL << i);
            }
        }

        cout << ans << '\n';
    }
};

struct Sub5 {
    ll dp[maxn];
    ll ans = (1LL << 41) - 1;

    bool check(ll x) {
        memset(dp + 1, 0x3f, sizeof(ll) * n);

        For (i, 1, n) {
            Ford (j, i - 1, 0) {
                if (((pref[i] - pref[j]) | x) <= x) {
                    chmin(dp[i], dp[j] + 1);
                }
            }
        }

        return dp[n] <= hi;
    }

    void solve() {
        Repd (i, 41) {
            if (check(ans ^ (1LL << i))) {
                ans ^= (1LL << i);
            }
        }

        cout << ans << '\n';
    }
};

signed main() {
    cin >> n >> lo >> hi;
    For (i, 1, n) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }

    if (lo == 1) {
        make_unique<Sub5>()->solve();
    }
    else {
        make_unique<Sub4>()->solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 3 ms 4172 KB Output is correct
18 Correct 3 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 3 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 3 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 3 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 3 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 2 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 3 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 3 ms 4172 KB Output is correct
15 Correct 2 ms 4172 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4172 KB Output is correct
20 Correct 2 ms 4172 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4172 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 320 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 316 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 2 ms 332 KB Output is correct
64 Correct 3 ms 4172 KB Output is correct
65 Correct 3 ms 4172 KB Output is correct
66 Correct 3 ms 4172 KB Output is correct
67 Correct 5 ms 4176 KB Output is correct
68 Correct 8 ms 4172 KB Output is correct
69 Correct 13 ms 4172 KB Output is correct
70 Correct 13 ms 4172 KB Output is correct
71 Correct 2 ms 4172 KB Output is correct
72 Correct 13 ms 4172 KB Output is correct
73 Correct 11 ms 4156 KB Output is correct
74 Correct 11 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 9 ms 332 KB Output is correct
53 Correct 14 ms 344 KB Output is correct
54 Correct 31 ms 344 KB Output is correct
55 Correct 23 ms 332 KB Output is correct
56 Correct 88 ms 332 KB Output is correct
57 Correct 85 ms 336 KB Output is correct
58 Correct 90 ms 332 KB Output is correct
59 Correct 87 ms 332 KB Output is correct
60 Correct 96 ms 452 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 13 ms 332 KB Output is correct
63 Correct 32 ms 332 KB Output is correct
64 Correct 24 ms 348 KB Output is correct
65 Correct 50 ms 352 KB Output is correct
66 Correct 70 ms 332 KB Output is correct
67 Correct 89 ms 332 KB Output is correct
68 Correct 98 ms 452 KB Output is correct
69 Correct 90 ms 332 KB Output is correct