답안 #660940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660940 2022-11-23T15:21:09 Z danikoynov Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 468 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll maxn = 1010, maxbit = 62;

ll n, A, B, f[maxbit], aw[maxn];
ll dp[101][101][2], fp[maxn][2];
ll a[maxn];
void solve()
{
    cin >> n >> A >> B;
    for (ll i = 1; i <= n; i ++)
        cin >> a[i];

    if (A == 1)
    {
        for (ll bit = maxbit - 1; bit >= 0; bit --)
        {
            for (int i = 0; i <= n; i ++)
                fp[i][0] = fp[i][1] = n + 1;
            fp[0][0] = fp[0][1] = 0;
            for (int i = 1; i <= n; i ++)
            {
                ll sum = 0;
                for (int k = i; k > 0; k --)
                {
                    sum = sum + a[k];
                    bool done = false;
                    for (ll fbit = maxbit - 1; fbit > bit; fbit --)
                    {
                        if ((sum & ((ll)(1) << fbit)) > 0 && f[fbit] == 0)
                        {
                            done = true;
                            break;
                        }
                    }
                    if (done)
                        continue;

                    fp[i][1] = min(fp[i][1], fp[k - 1][1] + 1);


                    if ((sum & ((ll)(1) << bit)) > 0)
                        continue;
                    fp[i][0] = min(fp[i][0], fp[k - 1][0] + 1);
                }


            }

                ll st = 1;
                if (fp[n][0] <= B)
                    st = 0;
                f[bit] = st;
                ///cout << bit << " " << st << " " << fp[n][0] << endl;


        }
        ll ans = 0;
        for (ll bit = 0; bit < maxbit; bit ++)
            if (f[bit])
                ans = ans + ((ll)(1) << bit);

        cout << ans << endl;
        return;
    }
    for (ll i = A; i <= B; i ++)
        aw[i] = 1;
    /// fix bit
    for (ll bit = maxbit - 1; bit >= 0; bit --)
    {
        dp[0][0][0] = dp[0][0][1] = 1;
        for (ll i = 1; i <= n; i ++)
            for (ll j = 1; j <= B; j ++)
                dp[i][j][0] = dp[i][j][1] = 0;

        for (ll i = 1; i <= n; i ++)
        {
            ll sum = 0;
            for (ll k = i; k > 0; k --)
            {
                sum += a[k];
                bool done = false;
                for (ll fbit = maxbit - 1; fbit > bit; fbit --)
                {
                    if ((sum & ((ll)(1) << fbit)) > 0 && f[fbit] == 0)
                    {
                        done = true;
                        break;
                    }
                }
                if (done)
                    continue;

                for (ll j = 1; j <= B; j ++)
                {
                    if (dp[k - 1][j - 1][1] == 1)
                        dp[i][j][1] = 1;
                }

                if ((sum & ((ll)(1) << bit)) > 0)
                    continue;

                for (ll j = 1; j <= B; j ++)
                {
                    if (dp[k - 1][j - 1][0] == 1)
                        dp[i][j][0] = 1;
                }

            }

        }
        ll st = 1;
        for (ll j = A; j <= B; j ++)
        {
            if (aw[j] && dp[n][j][0] == 1)
                st = 0;
        }

        if (st == 1)
        {
            f[bit] = 1;
            for (ll j = A; j <= B; j ++)
                aw[j] = min(aw[j], dp[n][j][1]);
        }
        else
        {
            for (ll j = A; j <= B; j ++)
                aw[j] = min(aw[j], dp[n][j][0]);
        }
        //exit(0);
    }

    ll ans = 0;
    for (ll bit = 0; bit < maxbit; bit ++)
        if (f[bit])
            ans = ans + ((ll)(1) << bit);

    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}
/**
6 1 2
8 1 2 1 5 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 2 ms 304 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 3 ms 212 KB Output is correct
30 Correct 3 ms 308 KB Output is correct
31 Correct 4 ms 308 KB Output is correct
32 Correct 4 ms 212 KB Output is correct
33 Correct 4 ms 316 KB Output is correct
34 Correct 4 ms 212 KB Output is correct
35 Correct 4 ms 304 KB Output is correct
36 Correct 4 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 3 ms 212 KB Output is correct
18 Correct 4 ms 308 KB Output is correct
19 Correct 4 ms 212 KB Output is correct
20 Correct 4 ms 312 KB Output is correct
21 Correct 4 ms 212 KB Output is correct
22 Correct 4 ms 312 KB Output is correct
23 Correct 4 ms 212 KB Output is correct
24 Correct 4 ms 212 KB Output is correct
25 Correct 7 ms 216 KB Output is correct
26 Correct 8 ms 212 KB Output is correct
27 Correct 11 ms 316 KB Output is correct
28 Correct 13 ms 312 KB Output is correct
29 Correct 12 ms 312 KB Output is correct
30 Correct 14 ms 212 KB Output is correct
31 Correct 13 ms 316 KB Output is correct
32 Correct 13 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 2 ms 212 KB Output is correct
40 Correct 3 ms 212 KB Output is correct
41 Correct 4 ms 212 KB Output is correct
42 Correct 4 ms 212 KB Output is correct
43 Correct 4 ms 300 KB Output is correct
44 Correct 4 ms 212 KB Output is correct
45 Correct 4 ms 212 KB Output is correct
46 Correct 4 ms 212 KB Output is correct
47 Correct 4 ms 212 KB Output is correct
48 Correct 7 ms 312 KB Output is correct
49 Correct 8 ms 340 KB Output is correct
50 Correct 11 ms 212 KB Output is correct
51 Correct 13 ms 304 KB Output is correct
52 Correct 13 ms 320 KB Output is correct
53 Correct 14 ms 312 KB Output is correct
54 Correct 13 ms 300 KB Output is correct
55 Correct 13 ms 308 KB Output is correct
56 Correct 3 ms 308 KB Output is correct
57 Correct 7 ms 212 KB Output is correct
58 Correct 9 ms 212 KB Output is correct
59 Correct 10 ms 312 KB Output is correct
60 Correct 10 ms 308 KB Output is correct
61 Correct 12 ms 312 KB Output is correct
62 Correct 11 ms 308 KB Output is correct
63 Correct 12 ms 308 KB Output is correct
64 Correct 55 ms 436 KB Output is correct
65 Correct 5 ms 340 KB Output is correct
66 Correct 7 ms 340 KB Output is correct
67 Correct 12 ms 340 KB Output is correct
68 Correct 24 ms 440 KB Output is correct
69 Correct 39 ms 440 KB Output is correct
70 Correct 39 ms 340 KB Output is correct
71 Correct 13 ms 468 KB Output is correct
72 Correct 44 ms 432 KB Output is correct
73 Correct 37 ms 432 KB Output is correct
74 Correct 39 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 3 ms 212 KB Output is correct
28 Correct 3 ms 212 KB Output is correct
29 Correct 4 ms 212 KB Output is correct
30 Correct 4 ms 212 KB Output is correct
31 Correct 4 ms 212 KB Output is correct
32 Correct 4 ms 308 KB Output is correct
33 Correct 4 ms 212 KB Output is correct
34 Correct 4 ms 212 KB Output is correct
35 Correct 6 ms 304 KB Output is correct
36 Correct 8 ms 212 KB Output is correct
37 Correct 14 ms 304 KB Output is correct
38 Correct 16 ms 292 KB Output is correct
39 Correct 14 ms 308 KB Output is correct
40 Correct 17 ms 312 KB Output is correct
41 Correct 13 ms 308 KB Output is correct
42 Correct 13 ms 312 KB Output is correct
43 Correct 3 ms 212 KB Output is correct
44 Correct 7 ms 212 KB Output is correct
45 Correct 9 ms 212 KB Output is correct
46 Correct 11 ms 304 KB Output is correct
47 Correct 10 ms 212 KB Output is correct
48 Correct 12 ms 308 KB Output is correct
49 Correct 12 ms 316 KB Output is correct
50 Correct 11 ms 316 KB Output is correct
51 Correct 11 ms 216 KB Output is correct
52 Correct 297 ms 312 KB Output is correct
53 Correct 495 ms 312 KB Output is correct
54 Correct 914 ms 316 KB Output is correct
55 Correct 849 ms 424 KB Output is correct
56 Execution timed out 1085 ms 340 KB Time limit exceeded
57 Halted 0 ms 0 KB -