Submission #507173

# Submission time Handle Problem Language Result Execution time Memory
507173 2022-01-12T09:30:08 Z Aldas25 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
291 ms 11124 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;

const int MAXN = 2100;
const ll INF = (ll)1e17;

int n, a, b;
ll y[MAXN];
ll pref[MAXN];
bool dp[MAXN][MAXN];

bool check2 (ll mask) {
   // cout << " mask = " << mask << endl;

    FOR(i, 0, n) FOR(g, 0, n) dp[i][g] = false;

    dp[0][0] = true;

    FOR(i, 1, n) FOR(g, 1, i) {
        FOR(j, g-1, i-1) {
            if (!dp[j][g-1]) continue;
            ll sum = pref[i]-pref[j];
            if (sum & mask) continue;
            dp[i][g] = true;
            //cout << " i = " << i << " g = " << g << " is true  for j = " << j << endl;
            break;
        }
    }

    FOR(x, a, b)
        if (dp[n][x])
            return true;
    return false;
}

vi adj[MAXN];
int d[MAXN];

bool check1 (ll mask) {
    FOR(i, 0, n) adj[i].clear();
    FOR(i, 0, n) FOR(j, 0, i-1) {
        ll sum = (pref[i]-pref[j]);
        if (sum & mask)
            continue;
        adj[j].pb(i);
    }

    FOR(i, 0, n) d[i] = -1;
    d[0] = 0;
    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : adj[v]) {
            if (d[u] == -1) {
                d[u] = d[v]+1;
                q.push(u);
            }
        }
    }


    if (a <= d[n] && d[n] <= b)
        return true;
    else return false;
}

int main()
{
    FAST_IO;

    cin >> n >> a >> b;
    FOR(i, 1, n) cin >> y[i];
    FOR(i, 1, n) pref[i] = pref[i-1] + y[i];

    bool solve1 = (a==1);

    ll ans = 0;
    for (ll k = 50; k >= 0; k--) {
        ll cur = ans + (1ll<<k) - 1ll;
        ll inv = ~cur;
        if (solve1 && !check1(inv))
            ans += (1ll << k);
        if (!solve1 && !check2(inv))
            ans += (1ll << k);
    }

    cout << ans << "\n";

    return 0;
}

/*
in:
6 1 3
8 1 2 1 5 4
ans: 11

in:
6 1 6
8 1 2 1 5 4

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 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 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 372 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 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 1 ms 332 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 372 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 0 ms 372 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 1 ms 372 KB Output is correct
30 Correct 1 ms 368 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 352 KB Output is correct
33 Correct 1 ms 360 KB Output is correct
34 Correct 1 ms 360 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 1 ms 372 KB Output is correct
2 Correct 0 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 1 ms 352 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 372 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 368 KB Output is correct
15 Correct 0 ms 364 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 0 ms 332 KB Output is correct
20 Correct 1 ms 376 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 372 KB Output is correct
28 Correct 1 ms 376 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 368 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 364 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 1 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 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 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 1 ms 372 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 376 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 368 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 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 368 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 348 KB Output is correct
28 Correct 1 ms 372 KB Output is correct
29 Correct 1 ms 372 KB Output is correct
30 Correct 2 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 1 ms 332 KB Output is correct
2 Correct 1 ms 372 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 1 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 372 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 368 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 372 KB Output is correct
17 Correct 1 ms 368 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 372 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 372 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 372 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 376 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 368 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 372 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 368 KB Output is correct
39 Correct 1 ms 352 KB Output is correct
40 Correct 1 ms 368 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 376 KB Output is correct
48 Correct 1 ms 372 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 372 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 2 ms 368 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 1 ms 332 KB Output is correct
64 Correct 2 ms 460 KB Output is correct
65 Correct 1 ms 460 KB Output is correct
66 Correct 3 ms 460 KB Output is correct
67 Correct 4 ms 460 KB Output is correct
68 Correct 6 ms 492 KB Output is correct
69 Correct 6 ms 596 KB Output is correct
70 Correct 8 ms 588 KB Output is correct
71 Correct 5 ms 588 KB Output is correct
72 Correct 6 ms 460 KB Output is correct
73 Correct 7 ms 588 KB Output is correct
74 Correct 8 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 1 ms 368 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 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 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 368 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 368 KB Output is correct
21 Correct 0 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 268 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 372 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 2 ms 332 KB Output is correct
37 Correct 1 ms 376 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 372 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 372 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 1 ms 372 KB Output is correct
47 Correct 2 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 18 ms 1272 KB Output is correct
53 Correct 28 ms 1996 KB Output is correct
54 Correct 49 ms 2940 KB Output is correct
55 Correct 54 ms 3020 KB Output is correct
56 Correct 236 ms 11028 KB Output is correct
57 Correct 223 ms 11008 KB Output is correct
58 Correct 287 ms 10988 KB Output is correct
59 Correct 227 ms 11024 KB Output is correct
60 Correct 252 ms 11016 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 27 ms 2016 KB Output is correct
63 Correct 53 ms 3048 KB Output is correct
64 Correct 67 ms 3020 KB Output is correct
65 Correct 91 ms 6220 KB Output is correct
66 Correct 154 ms 8916 KB Output is correct
67 Correct 245 ms 11076 KB Output is correct
68 Correct 291 ms 11004 KB Output is correct
69 Correct 209 ms 11124 KB Output is correct