Submission #1016173

# Submission time Handle Problem Language Result Execution time Memory
1016173 2024-07-07T13:19:20 Z andrei_iorgulescu Bali Sculptures (APIO15_sculpture) C++14
100 / 100
201 ms 23388 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int inf = 1e18;

int n,a,b,v[2005];
int s[2005][2005];
bool dp[105][105];
int d[2005];

bool pot(int x)
{
    if (a != 1)
    {
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++)
                dp[i][j] = false;
        dp[0][0] = true;
        for (int j = 1; j <= n; j++)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int q = 1; q <= i; q++)
                    if ((s[q][i] & x) == 0 and dp[j - 1][q - 1])
                        dp[j][i] = true;
            }
        }
        for (int i = a; i <= b; i++)
            if (dp[i][n] == true)
                return true;
        return false;
    }
    else
    {
        for (int i = 0; i <= 2000; i++)
            d[i] = inf;
        d[0] = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int q = 1; q <= i; q++)
            {
                if ((s[q][i] & x) == 0)
                    d[i] = min(d[i],1 + d[q - 1]);
            }
        }
        if (d[n] <= b)
            return true;
        return false;
    }
}

signed main()
{
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    for (int i = 1; i <= n; i++)
    {
        s[i][i] = v[i];
        for (int j = i + 1; j <= n; j++)
            s[i][j] = s[i][j - 1] + v[j];
    }
    int ans = 0;
    for (int bit = 50; bit >= 0; bit--)
    {
        int chk = ans + (1ll << bit);
        if (pot(chk))
            ans = chk;
    }
    cout << (1ll << 51) - 1 - ans;
    return 0;
}

/*
6 1 3
8 1 2 1 5 4
*/

/**
Idee: incerc sa imi construiesc raspunsul bit cu bit, la un pas am deja dintr-un prefix de biti unii pe care sigur nu ii iau
Deci voi face log verificari de tipul: pot sa impart sirul in [A B] intervale, suma fiecaruia sa dea and-ul cu x = 0?

Daca A != 1 -> Fac in n^3 o dinamica gen: dp[j][i] = pot sa impart primele i in j grupe sa respecte conditia?
dp[j][i] vine din dp[j - 1][q < i] a.i (sum(q + 1...i) & x) == 0

Daca A == 1 -> Fac in n^2 o dinamica gen: dp[i] = -1 daca nu pot imparti primele i in grupe sa dea and-ul 0 cu x, sau nr minim de grupe altfel
dp[i] vine din dp[j < i] a.i (sum(q + 1...i) & x) == 0, practic o sa fie -1 daca nu vine din niciuna >= 0 sau 1 + aia minima altfel
**/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2488 KB Output is correct
13 Correct 1 ms 2492 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 444 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2492 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2488 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2492 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2492 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2492 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2648 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 2 ms 2392 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2392 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 20 ms 2396 KB Output is correct
65 Correct 5 ms 2396 KB Output is correct
66 Correct 8 ms 2544 KB Output is correct
67 Correct 14 ms 2556 KB Output is correct
68 Correct 22 ms 2396 KB Output is correct
69 Correct 29 ms 2392 KB Output is correct
70 Correct 28 ms 2396 KB Output is correct
71 Correct 29 ms 2396 KB Output is correct
72 Correct 29 ms 2392 KB Output is correct
73 Correct 28 ms 2392 KB Output is correct
74 Correct 29 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2532 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2492 KB Output is correct
42 Correct 1 ms 2404 KB Output is correct
43 Correct 1 ms 2408 KB Output is correct
44 Correct 1 ms 2404 KB Output is correct
45 Correct 1 ms 2400 KB Output is correct
46 Correct 1 ms 2400 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2400 KB Output is correct
52 Correct 8 ms 6236 KB Output is correct
53 Correct 14 ms 6496 KB Output is correct
54 Correct 33 ms 9568 KB Output is correct
55 Correct 25 ms 8800 KB Output is correct
56 Correct 166 ms 23100 KB Output is correct
57 Correct 142 ms 23136 KB Output is correct
58 Correct 152 ms 23136 KB Output is correct
59 Correct 148 ms 23136 KB Output is correct
60 Correct 169 ms 23388 KB Output is correct
61 Correct 1 ms 2400 KB Output is correct
62 Correct 13 ms 6496 KB Output is correct
63 Correct 27 ms 8800 KB Output is correct
64 Correct 26 ms 8800 KB Output is correct
65 Correct 52 ms 13920 KB Output is correct
66 Correct 99 ms 19064 KB Output is correct
67 Correct 157 ms 23156 KB Output is correct
68 Correct 167 ms 23136 KB Output is correct
69 Correct 201 ms 23132 KB Output is correct