답안 #270483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270483 2020-08-17T16:25:36 Z BeanZ Bali Sculptures (APIO15_sculpture) C++14
100 / 100
151 ms 2144 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)

int N, A, B;
int D[2001];
int maxD;

typedef long long ll;

const ll INF = 1LL << 57LL;

namespace subtask1
{
    ll ans;

    void go(int pos, int parts, ll sum, ll orr)
    {
        if (pos == N)
        {
            if (A <= parts && parts <= B)
                ans = min(ans, sum | orr);
            return;
        }

        // take
        go(pos + 1, parts, sum + D[pos], orr);

        // make new partition
        go(pos + 1, parts + 1, D[pos], orr | sum);
    }

    ll solve()
    {
        ans = INF;
        go(1, 1, D[0], 0);

        return ans;
    }

    bool satisfies()
    {
        return true
            && 1 <= N && N <= 20
            && 1 <= A && A <= B && B <= N
            && 0 <= maxD && maxD <= 1000000000
        ;
    }
}

namespace subtask2
{
    bool dp[51][1<<9][21];

    ll solve()
    {
        dp[0][0][0] = true;
        REP(i, N) REP(orr, 1<<9) REP(parts, B)
        {
            int sum = 0;
            FOR(j, i, N)
            {
                sum += D[j];
                dp[j + 1][orr | sum][parts + 1] |= dp[i][orr][parts];
            }
        }

        REP(orr, 1<<9) FOR(parts, A, B+1)
            if (dp[N][orr][parts])
                return orr;
    }

    bool satisfies()
    {
        return true
            && 1 <= N && N <= 50
            && 1 <= A && A <= B && B <= min(20, N)
            && 0 <= maxD && maxD <= 10
        ;
    }
}

namespace subtask3
{
    ll dp[101][1<<11];

    ll solve()
    {
        REP(i, N+1) REP(orr, 1<<11)
            dp[i][orr] = INF;

        dp[0][0] = 0;
        REP(i, N) REP(orr, 1<<11)
        {
            int sum = 0;
            FOR(j, i, N)
            {
                sum += D[j];
                dp[j + 1][orr | sum] = min(dp[j + 1][orr | sum], 1 + dp[i][orr]);
            }
        }

        REP(orr, 1<<11)
            if (dp[N][orr] <= B)
                return orr;
    }

    bool satisfies()
    {
        return true
            && 1 <= N && N <= 100
            && A == 1
            && 1 <= B <= N
            && 0 <= maxD && maxD <= 20
        ;
    }
}

namespace subtask4
{
    bool dp[101][101];
    ll ans;

    bool can()
    {
        memset(dp, false, sizeof dp);

        dp[0][0] = true;
        REP(i, N) REP(parts, B)
        {
            ll sum = 0;
            FOR(j, i, N)
            {
                sum += D[j];
                if ((sum | ans) == ans)
                    dp[j + 1][parts + 1] |= dp[i][parts];
            }
        }

        FOR(parts, A, B+1)
            if (dp[N][parts])
                return true;
        return false;
    }

    ll solve()
    {
        ans = (1LL<<57) - 1;
        for (ll bit = 56; bit >= 0; bit--)
        {
            ans ^= 1LL<<bit;

            if (!can())
                ans |= 1LL<<bit;
        }

        return ans;
    }

    bool satisfies()
    {
        return true
            && 1 <= N && N <= 100
            && 1 <= A && A <= B && B <= N
            && 0 <= maxD && maxD <= 1000000000
        ;
    }
}

namespace subtask5
{
    ll dp[2001];
    ll ans;

    bool can()
    {
        REP(i, N+1)
            dp[i] = INF;

        dp[0] = 0;
        REP(i, N)
        {
            ll sum = 0;
            FOR(j, i, N)
            {
                sum += D[j];
                if ((sum | ans) == ans)
                    dp[j + 1] = min(dp[j + 1], 1 + dp[i]);
            }
        }

        return dp[N] <= B;
    }

    ll solve()
    {
        ans = (1LL<<57) - 1;
        for (ll bit = 56; bit >= 0; bit--)
        {
            ans ^= 1LL<<bit;

            if (!can())
                ans |= 1LL<<bit;
        }

        return ans;
    }

    bool satisfies()
    {
        return true
            && 1 <= N && N <= 2000
            && A == 1
            && 1 <= B && B <= N
            && 0 <= maxD && maxD <= 1000000000
        ;
    }
}

function<bool()> validators[] = {
    subtask1::satisfies,
    subtask2::satisfies,
    subtask3::satisfies,
    subtask4::satisfies,
    subtask5::satisfies,
};

function<ll()> solvers[] = {
    subtask1::solve,
    subtask2::solve,
    subtask3::solve,
    subtask4::solve,
    subtask5::solve,
};

int main()
{
    cin >> N >> A >> B;
    REP(i, N)
        cin >> D[i];
    maxD = *max_element(D, D+N);

    vector<ll> answers;

    REP(i, 5)
        if (validators[i]())
            answers.push_back(solvers[i]());

    sort(answers.begin(), answers.end());
    assert(answers.front() == answers.back());
    cout << answers.front() << endl;
}

Compilation message

sculpture.cpp: In function 'bool subtask3::satisfies()':
sculpture.cpp:115:18: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
  115 |             && 1 <= B <= N
      |                ~~^~~~
sculpture.cpp: In function 'll subtask2::solve()':
sculpture.cpp:73:5: warning: control reaches end of non-void function [-Wreturn-type]
   73 |     }
      |     ^
sculpture.cpp: In function 'll subtask3::solve()':
sculpture.cpp:108:5: warning: control reaches end of non-void function [-Wreturn-type]
  108 |     }
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 9 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 6 ms 948 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 18 ms 896 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 10 ms 512 KB Output is correct
22 Correct 9 ms 512 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 5 ms 544 KB Output is correct
25 Correct 9 ms 512 KB Output is correct
26 Correct 12 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 8 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 7 ms 896 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 18 ms 896 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 9 ms 512 KB Output is correct
23 Correct 11 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 8 ms 512 KB Output is correct
26 Correct 13 ms 512 KB Output is correct
27 Correct 18 ms 896 KB Output is correct
28 Correct 15 ms 1024 KB Output is correct
29 Correct 25 ms 1408 KB Output is correct
30 Correct 65 ms 1528 KB Output is correct
31 Correct 97 ms 1852 KB Output is correct
32 Correct 101 ms 1784 KB Output is correct
33 Correct 19 ms 1664 KB Output is correct
34 Correct 101 ms 1656 KB Output is correct
35 Correct 87 ms 1656 KB Output is correct
36 Correct 55 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 8 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 9 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 18 ms 896 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 15 ms 1024 KB Output is correct
16 Correct 21 ms 1408 KB Output is correct
17 Correct 65 ms 1528 KB Output is correct
18 Correct 98 ms 1656 KB Output is correct
19 Correct 98 ms 1656 KB Output is correct
20 Correct 18 ms 1664 KB Output is correct
21 Correct 98 ms 1664 KB Output is correct
22 Correct 87 ms 1784 KB Output is correct
23 Correct 56 ms 1660 KB Output is correct
24 Correct 16 ms 1152 KB Output is correct
25 Correct 25 ms 1408 KB Output is correct
26 Correct 40 ms 1656 KB Output is correct
27 Correct 65 ms 1792 KB Output is correct
28 Correct 95 ms 1920 KB Output is correct
29 Correct 96 ms 1920 KB Output is correct
30 Correct 57 ms 1920 KB Output is correct
31 Correct 77 ms 1920 KB Output is correct
32 Correct 87 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 8 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 7 ms 896 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 8 ms 1024 KB Output is correct
13 Correct 20 ms 896 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 416 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 10 ms 600 KB Output is correct
22 Correct 8 ms 616 KB Output is correct
23 Correct 8 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 8 ms 512 KB Output is correct
26 Correct 13 ms 512 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 4 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 18 ms 888 KB Output is correct
38 Correct 15 ms 1024 KB Output is correct
39 Correct 23 ms 1408 KB Output is correct
40 Correct 65 ms 1532 KB Output is correct
41 Correct 99 ms 1656 KB Output is correct
42 Correct 88 ms 1656 KB Output is correct
43 Correct 21 ms 1724 KB Output is correct
44 Correct 99 ms 1656 KB Output is correct
45 Correct 86 ms 1776 KB Output is correct
46 Correct 57 ms 1668 KB Output is correct
47 Correct 17 ms 1152 KB Output is correct
48 Correct 25 ms 1432 KB Output is correct
49 Correct 40 ms 1536 KB Output is correct
50 Correct 66 ms 1912 KB Output is correct
51 Correct 110 ms 2040 KB Output is correct
52 Correct 99 ms 2144 KB Output is correct
53 Correct 57 ms 1920 KB Output is correct
54 Correct 79 ms 2052 KB Output is correct
55 Correct 89 ms 1920 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 26 ms 384 KB Output is correct
59 Correct 46 ms 384 KB Output is correct
60 Correct 50 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 45 ms 384 KB Output is correct
63 Correct 44 ms 384 KB Output is correct
64 Correct 33 ms 384 KB Output is correct
65 Correct 3 ms 384 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 7 ms 384 KB Output is correct
68 Correct 21 ms 384 KB Output is correct
69 Correct 46 ms 504 KB Output is correct
70 Correct 47 ms 536 KB Output is correct
71 Correct 2 ms 384 KB Output is correct
72 Correct 44 ms 384 KB Output is correct
73 Correct 33 ms 384 KB Output is correct
74 Correct 30 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 8 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 8 ms 896 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 18 ms 896 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 18 ms 964 KB Output is correct
25 Correct 15 ms 1056 KB Output is correct
26 Correct 21 ms 1424 KB Output is correct
27 Correct 64 ms 1460 KB Output is correct
28 Correct 99 ms 1656 KB Output is correct
29 Correct 101 ms 1784 KB Output is correct
30 Correct 19 ms 1664 KB Output is correct
31 Correct 97 ms 1800 KB Output is correct
32 Correct 86 ms 1632 KB Output is correct
33 Correct 57 ms 1656 KB Output is correct
34 Correct 16 ms 1152 KB Output is correct
35 Correct 25 ms 1408 KB Output is correct
36 Correct 40 ms 1536 KB Output is correct
37 Correct 65 ms 1792 KB Output is correct
38 Correct 96 ms 1920 KB Output is correct
39 Correct 99 ms 2040 KB Output is correct
40 Correct 58 ms 1920 KB Output is correct
41 Correct 84 ms 1920 KB Output is correct
42 Correct 86 ms 1920 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 8 ms 384 KB Output is correct
45 Correct 22 ms 384 KB Output is correct
46 Correct 48 ms 384 KB Output is correct
47 Correct 48 ms 388 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 68 ms 384 KB Output is correct
50 Correct 46 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 12 ms 384 KB Output is correct
53 Correct 22 ms 384 KB Output is correct
54 Correct 37 ms 384 KB Output is correct
55 Correct 42 ms 376 KB Output is correct
56 Correct 133 ms 384 KB Output is correct
57 Correct 148 ms 388 KB Output is correct
58 Correct 142 ms 504 KB Output is correct
59 Correct 133 ms 384 KB Output is correct
60 Correct 138 ms 304 KB Output is correct
61 Correct 1 ms 256 KB Output is correct
62 Correct 20 ms 384 KB Output is correct
63 Correct 41 ms 376 KB Output is correct
64 Correct 42 ms 384 KB Output is correct
65 Correct 69 ms 384 KB Output is correct
66 Correct 102 ms 388 KB Output is correct
67 Correct 138 ms 384 KB Output is correct
68 Correct 151 ms 388 KB Output is correct
69 Correct 129 ms 384 KB Output is correct