Submission #660942

# Submission time Handle Problem Language Result Execution time Memory
660942 2022-11-23T15:28:58 Z danikoynov Bali Sculptures (APIO15_sculpture) C++14
100 / 100
228 ms 472 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 = 2010, 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)
    {
        ll so_far = 0, to_rem = ((ll)(1) << maxbit) - 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];
                    ll psum = (sum & (~to_rem));
                    //cout << i << " " << k << " " << psum << endl;
                    if ((psum | so_far) != so_far)
                        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;
                so_far = so_far + f[bit] * ((ll)(1) << bit);
                to_rem = to_rem - ((ll)(1) << bit);
                //cout << bit << " " << st << " " << fp[n][0] << endl;
                //if (bit == 60)
                  //  exit(0);


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

        cout << so_far << 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 3
8 1 2 1 5 4
*/
# Verdict Execution time Memory 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 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 0 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 0 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 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 0 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 0 ms 268 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 340 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 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 308 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
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 1 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 212 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 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 340 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 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 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 0 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 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 296 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 2 ms 212 KB Output is correct
54 Correct 2 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 62 ms 432 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 25 ms 456 KB Output is correct
69 Correct 40 ms 460 KB Output is correct
70 Correct 37 ms 472 KB Output is correct
71 Correct 13 ms 340 KB Output is correct
72 Correct 43 ms 340 KB Output is correct
73 Correct 37 ms 464 KB Output is correct
74 Correct 37 ms 460 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 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 2 ms 212 KB Output is correct
39 Correct 2 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 312 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 22 ms 316 KB Output is correct
53 Correct 39 ms 328 KB Output is correct
54 Correct 63 ms 320 KB Output is correct
55 Correct 60 ms 332 KB Output is correct
56 Correct 217 ms 340 KB Output is correct
57 Correct 217 ms 356 KB Output is correct
58 Correct 225 ms 360 KB Output is correct
59 Correct 211 ms 360 KB Output is correct
60 Correct 228 ms 360 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 33 ms 212 KB Output is correct
63 Correct 67 ms 320 KB Output is correct
64 Correct 56 ms 316 KB Output is correct
65 Correct 110 ms 340 KB Output is correct
66 Correct 165 ms 348 KB Output is correct
67 Correct 219 ms 356 KB Output is correct
68 Correct 219 ms 372 KB Output is correct
69 Correct 213 ms 352 KB Output is correct