Submission #232918

# Submission time Handle Problem Language Result Execution time Memory
232918 2020-05-18T16:32:06 Z andreiomd Bali Sculptures (APIO15_sculpture) C++11
100 / 100
453 ms 512 KB
#include <iostream>

using namespace std;

const int NMAX = 2e3 + 5, INF = 1e9;

int N, A, B, Y[NMAX];

long long sp[NMAX], BitMask;

static inline void Read ()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> A >> B;

    for(int i = 1; i <= N; ++i)
        cin >> Y[i], sp[i] = sp[i - 1] + 1LL * Y[i];

    return;
}

auto Check = [] (int byte, long long Sum)
{
    if(Sum & (1LL << byte))
        return 0;

    Sum >>= (1LL * (byte + 1));

    if((Sum | BitMask) != BitMask)
        return 0;

    return 1;
};

static inline bool Ok_1 (int byte)
{
    bool dp[N + 1][N + 1];
    for(int i = 0; i <= N; ++i)
        for(int j = 0; j <= N; ++j)
            dp[i][j] = 0;

    dp[0][0] = 1;

    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= i; ++j)
            for(int k = 0; k < i && !dp[i][j]; ++k)
                if(dp[k][j - 1] && Check(byte, sp[i] - sp[k]))
                    dp[i][j] = 1;

    for(int i = A; i <= B; ++i)
        if(dp[N][i])
            return 1;

    return 0;
}

static inline bool Ok_2 (int byte)
{
    int dp[N + 5];

    dp[0] = 0;

    for(int i = 1; i <= N; ++i)
    {
        dp[i] = INF;

        for(int j = 0; j < i; ++j)
            if(Check(byte, sp[i] - sp[j]))
                dp[i] = min(dp[i], dp[j] + 1);
    }

    return (dp[N] <= B);
}

auto Ok = [] (int byte)
{
    if(N <= 1e2)
        return Ok_1(byte);

    return Ok_2(byte);
};

static inline void Solve ()
{
    long long ans = 0;

    for(int i = 40; i >= 0; --i)
    {
        bool Now = Ok(i);
        BitMask = (BitMask << 1LL);

        if(Now)
            continue;
        else
            ans += 1LL * (1LL << i), ++BitMask;
    }

    cout << ans << '\n';

    return;
}

int main()
{
    Read();

    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 308 KB Output is correct
10 Correct 5 ms 288 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 8 ms 384 KB Output is correct
33 Correct 6 ms 384 KB Output is correct
34 Correct 7 ms 384 KB Output is correct
35 Correct 7 ms 384 KB Output is correct
36 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 7 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 8 ms 384 KB Output is correct
21 Correct 7 ms 384 KB Output is correct
22 Correct 7 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
24 Correct 7 ms 384 KB Output is correct
25 Correct 9 ms 384 KB Output is correct
26 Correct 12 ms 384 KB Output is correct
27 Correct 16 ms 384 KB Output is correct
28 Correct 28 ms 384 KB Output is correct
29 Correct 20 ms 304 KB Output is correct
30 Correct 18 ms 384 KB Output is correct
31 Correct 30 ms 384 KB Output is correct
32 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 7 ms 384 KB Output is correct
42 Correct 7 ms 512 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 7 ms 384 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 7 ms 384 KB Output is correct
47 Correct 7 ms 384 KB Output is correct
48 Correct 9 ms 384 KB Output is correct
49 Correct 12 ms 384 KB Output is correct
50 Correct 16 ms 384 KB Output is correct
51 Correct 20 ms 400 KB Output is correct
52 Correct 19 ms 384 KB Output is correct
53 Correct 18 ms 384 KB Output is correct
54 Correct 19 ms 384 KB Output is correct
55 Correct 19 ms 384 KB Output is correct
56 Correct 8 ms 384 KB Output is correct
57 Correct 16 ms 384 KB Output is correct
58 Correct 20 ms 384 KB Output is correct
59 Correct 25 ms 384 KB Output is correct
60 Correct 26 ms 384 KB Output is correct
61 Correct 24 ms 384 KB Output is correct
62 Correct 25 ms 384 KB Output is correct
63 Correct 26 ms 384 KB Output is correct
64 Correct 15 ms 384 KB Output is correct
65 Correct 8 ms 384 KB Output is correct
66 Correct 11 ms 384 KB Output is correct
67 Correct 16 ms 384 KB Output is correct
68 Correct 22 ms 384 KB Output is correct
69 Correct 24 ms 384 KB Output is correct
70 Correct 27 ms 384 KB Output is correct
71 Correct 24 ms 384 KB Output is correct
72 Correct 24 ms 384 KB Output is correct
73 Correct 26 ms 384 KB Output is correct
74 Correct 27 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 6 ms 384 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 384 KB Output is correct
33 Correct 7 ms 384 KB Output is correct
34 Correct 7 ms 512 KB Output is correct
35 Correct 9 ms 384 KB Output is correct
36 Correct 12 ms 384 KB Output is correct
37 Correct 16 ms 384 KB Output is correct
38 Correct 20 ms 384 KB Output is correct
39 Correct 19 ms 384 KB Output is correct
40 Correct 18 ms 384 KB Output is correct
41 Correct 19 ms 384 KB Output is correct
42 Correct 19 ms 384 KB Output is correct
43 Correct 8 ms 384 KB Output is correct
44 Correct 17 ms 388 KB Output is correct
45 Correct 21 ms 384 KB Output is correct
46 Correct 24 ms 408 KB Output is correct
47 Correct 27 ms 384 KB Output is correct
48 Correct 24 ms 384 KB Output is correct
49 Correct 25 ms 384 KB Output is correct
50 Correct 26 ms 384 KB Output is correct
51 Correct 6 ms 384 KB Output is correct
52 Correct 42 ms 384 KB Output is correct
53 Correct 68 ms 384 KB Output is correct
54 Correct 118 ms 384 KB Output is correct
55 Correct 117 ms 384 KB Output is correct
56 Correct 453 ms 508 KB Output is correct
57 Correct 449 ms 504 KB Output is correct
58 Correct 278 ms 428 KB Output is correct
59 Correct 168 ms 384 KB Output is correct
60 Correct 177 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 66 ms 504 KB Output is correct
63 Correct 112 ms 384 KB Output is correct
64 Correct 113 ms 384 KB Output is correct
65 Correct 199 ms 508 KB Output is correct
66 Correct 282 ms 504 KB Output is correct
67 Correct 357 ms 508 KB Output is correct
68 Correct 354 ms 504 KB Output is correct
69 Correct 350 ms 384 KB Output is correct