Submission #45925

# Submission time Handle Problem Language Result Execution time Memory
45925 2018-04-16T13:38:59 Z antimirage Bali Sculptures (APIO15_sculpture) C++17
100 / 100
361 ms 11632 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2005;

int n, a, b, ar[N], cnt;

bool dp[N][N], u[N];

long long ans, sum, pref[N], Dp[N];

vector < vector <int> > g;
queue <int> q;

main()
{
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
        scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];

    if (n > 100)
    {
        for (int k = 40; k >= 0; k--)
        {
            g.clear();
            g.resize(n + 1);

            for (int i = 1; i <= n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if ( ( ans | ( ( (pref[i] - pref[j]) >> k) << k) ) == ans )
                        g[j].push_back(i);
                }
            }
            long long cur = (1LL << k);

            memset(Dp, 0, sizeof(Dp) );

            Dp[0] = 1;
            q.push(0);

            while (!q.empty())
            {
                int v = q.front();
                q.pop();
                for (auto to : g[v])
                {
                    if ( !Dp[to] )
                    {
                        Dp[to] = Dp[v] + 1;
                        q.push(to);
                    }
                }
            }
            bool fl = 0;

            if (Dp[n] == 0 || Dp[n] - 1 > b)
                ans += cur;
        }
        cout << ans << endl;
    }
    else
    {
        for (int k = 40; k >= 0; k--)
        {
            long long cur = (1LL << k);

            memset(dp, 0, sizeof(dp) );

            dp[0][0] = 1;

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int l = 1; l <= j; l++)
                    {
                        if ( ( ans | ( ( (pref[j] - pref[l - 1]) >> k) << k) ) == ans  )
                            dp[i][j] |= dp[i - 1][l - 1];
                    }
                }
            }
            bool fl = 0;

            for (int i = a; i <= b; i++)
                fl |= dp[i][n];

            if (!fl)
                ans += cur;
        }
        cout << ans << endl;
    }
}
/**
6 1 3
8 1 2 1 5 4
**/

Compilation message

sculpture.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
sculpture.cpp: In function 'int main()':
sculpture.cpp:65:18: warning: unused variable 'fl' [-Wunused-variable]
             bool fl = 0;
                  ^~
sculpture.cpp:28:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];
         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4216 KB Output is correct
2 Correct 15 ms 4328 KB Output is correct
3 Correct 14 ms 4404 KB Output is correct
4 Correct 14 ms 4460 KB Output is correct
5 Correct 14 ms 4460 KB Output is correct
6 Correct 15 ms 4504 KB Output is correct
7 Correct 13 ms 4504 KB Output is correct
8 Correct 16 ms 4504 KB Output is correct
9 Correct 13 ms 4504 KB Output is correct
10 Correct 14 ms 4536 KB Output is correct
11 Correct 13 ms 4536 KB Output is correct
12 Correct 13 ms 4536 KB Output is correct
13 Correct 14 ms 4536 KB Output is correct
14 Correct 13 ms 4536 KB Output is correct
15 Correct 15 ms 4544 KB Output is correct
16 Correct 13 ms 4544 KB Output is correct
17 Correct 16 ms 4544 KB Output is correct
18 Correct 15 ms 4544 KB Output is correct
19 Correct 14 ms 4544 KB Output is correct
20 Correct 17 ms 4544 KB Output is correct
21 Correct 16 ms 4588 KB Output is correct
22 Correct 16 ms 4588 KB Output is correct
23 Correct 17 ms 4588 KB Output is correct
24 Correct 15 ms 4588 KB Output is correct
25 Correct 16 ms 4588 KB Output is correct
26 Correct 16 ms 4588 KB Output is correct
27 Correct 16 ms 4588 KB Output is correct
28 Correct 15 ms 4588 KB Output is correct
29 Correct 16 ms 4588 KB Output is correct
30 Correct 15 ms 4588 KB Output is correct
31 Correct 16 ms 4588 KB Output is correct
32 Correct 17 ms 4588 KB Output is correct
33 Correct 17 ms 4588 KB Output is correct
34 Correct 14 ms 4588 KB Output is correct
35 Correct 16 ms 4588 KB Output is correct
36 Correct 16 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4588 KB Output is correct
2 Correct 16 ms 4588 KB Output is correct
3 Correct 16 ms 4588 KB Output is correct
4 Correct 16 ms 4588 KB Output is correct
5 Correct 16 ms 4588 KB Output is correct
6 Correct 16 ms 4588 KB Output is correct
7 Correct 16 ms 4588 KB Output is correct
8 Correct 17 ms 4588 KB Output is correct
9 Correct 17 ms 4588 KB Output is correct
10 Correct 14 ms 4588 KB Output is correct
11 Correct 16 ms 4588 KB Output is correct
12 Correct 16 ms 4588 KB Output is correct
13 Correct 14 ms 4588 KB Output is correct
14 Correct 14 ms 4588 KB Output is correct
15 Correct 14 ms 4588 KB Output is correct
16 Correct 14 ms 4604 KB Output is correct
17 Correct 15 ms 4604 KB Output is correct
18 Correct 15 ms 4604 KB Output is correct
19 Correct 14 ms 4604 KB Output is correct
20 Correct 15 ms 4604 KB Output is correct
21 Correct 17 ms 4604 KB Output is correct
22 Correct 17 ms 4604 KB Output is correct
23 Correct 15 ms 4604 KB Output is correct
24 Correct 15 ms 4608 KB Output is correct
25 Correct 16 ms 4608 KB Output is correct
26 Correct 16 ms 4608 KB Output is correct
27 Correct 14 ms 4608 KB Output is correct
28 Correct 16 ms 4608 KB Output is correct
29 Correct 16 ms 4608 KB Output is correct
30 Correct 21 ms 4608 KB Output is correct
31 Correct 25 ms 4608 KB Output is correct
32 Correct 26 ms 4608 KB Output is correct
33 Correct 25 ms 4608 KB Output is correct
34 Correct 26 ms 4608 KB Output is correct
35 Correct 25 ms 4608 KB Output is correct
36 Correct 21 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4608 KB Output is correct
2 Correct 13 ms 4608 KB Output is correct
3 Correct 15 ms 4608 KB Output is correct
4 Correct 13 ms 4608 KB Output is correct
5 Correct 15 ms 4608 KB Output is correct
6 Correct 15 ms 4608 KB Output is correct
7 Correct 13 ms 4608 KB Output is correct
8 Correct 13 ms 4608 KB Output is correct
9 Correct 17 ms 4608 KB Output is correct
10 Correct 16 ms 4608 KB Output is correct
11 Correct 13 ms 4608 KB Output is correct
12 Correct 15 ms 4608 KB Output is correct
13 Correct 17 ms 4608 KB Output is correct
14 Correct 14 ms 4608 KB Output is correct
15 Correct 14 ms 4608 KB Output is correct
16 Correct 16 ms 4608 KB Output is correct
17 Correct 22 ms 4608 KB Output is correct
18 Correct 21 ms 4608 KB Output is correct
19 Correct 24 ms 4608 KB Output is correct
20 Correct 25 ms 4608 KB Output is correct
21 Correct 21 ms 4608 KB Output is correct
22 Correct 20 ms 4608 KB Output is correct
23 Correct 24 ms 4608 KB Output is correct
24 Correct 28 ms 4608 KB Output is correct
25 Correct 29 ms 4608 KB Output is correct
26 Correct 51 ms 4608 KB Output is correct
27 Correct 59 ms 4608 KB Output is correct
28 Correct 95 ms 4608 KB Output is correct
29 Correct 78 ms 4608 KB Output is correct
30 Correct 113 ms 4608 KB Output is correct
31 Correct 64 ms 4608 KB Output is correct
32 Correct 64 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4608 KB Output is correct
2 Correct 15 ms 4608 KB Output is correct
3 Correct 15 ms 4608 KB Output is correct
4 Correct 15 ms 4608 KB Output is correct
5 Correct 13 ms 4608 KB Output is correct
6 Correct 13 ms 4608 KB Output is correct
7 Correct 13 ms 4608 KB Output is correct
8 Correct 14 ms 4608 KB Output is correct
9 Correct 16 ms 4608 KB Output is correct
10 Correct 13 ms 4608 KB Output is correct
11 Correct 16 ms 4608 KB Output is correct
12 Correct 14 ms 4608 KB Output is correct
13 Correct 16 ms 4608 KB Output is correct
14 Correct 15 ms 4608 KB Output is correct
15 Correct 14 ms 4608 KB Output is correct
16 Correct 13 ms 4608 KB Output is correct
17 Correct 15 ms 4608 KB Output is correct
18 Correct 15 ms 4608 KB Output is correct
19 Correct 15 ms 4608 KB Output is correct
20 Correct 15 ms 4608 KB Output is correct
21 Correct 16 ms 4608 KB Output is correct
22 Correct 15 ms 4608 KB Output is correct
23 Correct 15 ms 4608 KB Output is correct
24 Correct 14 ms 4608 KB Output is correct
25 Correct 16 ms 4608 KB Output is correct
26 Correct 15 ms 4608 KB Output is correct
27 Correct 14 ms 4608 KB Output is correct
28 Correct 15 ms 4608 KB Output is correct
29 Correct 15 ms 4608 KB Output is correct
30 Correct 14 ms 4608 KB Output is correct
31 Correct 13 ms 4608 KB Output is correct
32 Correct 15 ms 4608 KB Output is correct
33 Correct 14 ms 4608 KB Output is correct
34 Correct 13 ms 4608 KB Output is correct
35 Correct 14 ms 4608 KB Output is correct
36 Correct 16 ms 4608 KB Output is correct
37 Correct 17 ms 4608 KB Output is correct
38 Correct 17 ms 4608 KB Output is correct
39 Correct 18 ms 4608 KB Output is correct
40 Correct 18 ms 4608 KB Output is correct
41 Correct 26 ms 4608 KB Output is correct
42 Correct 26 ms 4608 KB Output is correct
43 Correct 20 ms 4608 KB Output is correct
44 Correct 20 ms 4608 KB Output is correct
45 Correct 20 ms 4608 KB Output is correct
46 Correct 20 ms 4608 KB Output is correct
47 Correct 28 ms 4608 KB Output is correct
48 Correct 31 ms 4608 KB Output is correct
49 Correct 52 ms 4608 KB Output is correct
50 Correct 54 ms 4608 KB Output is correct
51 Correct 64 ms 4608 KB Output is correct
52 Correct 74 ms 4608 KB Output is correct
53 Correct 65 ms 4608 KB Output is correct
54 Correct 65 ms 4608 KB Output is correct
55 Correct 66 ms 4608 KB Output is correct
56 Correct 23 ms 4608 KB Output is correct
57 Correct 35 ms 4608 KB Output is correct
58 Correct 57 ms 4608 KB Output is correct
59 Correct 66 ms 4608 KB Output is correct
60 Correct 68 ms 4608 KB Output is correct
61 Correct 71 ms 4608 KB Output is correct
62 Correct 69 ms 4608 KB Output is correct
63 Correct 60 ms 4608 KB Output is correct
64 Correct 55 ms 4608 KB Output is correct
65 Correct 22 ms 4608 KB Output is correct
66 Correct 27 ms 4608 KB Output is correct
67 Correct 34 ms 4608 KB Output is correct
68 Correct 57 ms 4608 KB Output is correct
69 Correct 66 ms 4608 KB Output is correct
70 Correct 71 ms 4608 KB Output is correct
71 Correct 61 ms 4608 KB Output is correct
72 Correct 79 ms 4608 KB Output is correct
73 Correct 60 ms 4608 KB Output is correct
74 Correct 82 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4608 KB Output is correct
2 Correct 17 ms 4608 KB Output is correct
3 Correct 16 ms 4608 KB Output is correct
4 Correct 16 ms 4608 KB Output is correct
5 Correct 13 ms 4608 KB Output is correct
6 Correct 16 ms 4608 KB Output is correct
7 Correct 15 ms 4608 KB Output is correct
8 Correct 15 ms 4608 KB Output is correct
9 Correct 14 ms 4608 KB Output is correct
10 Correct 15 ms 4608 KB Output is correct
11 Correct 15 ms 4608 KB Output is correct
12 Correct 13 ms 4608 KB Output is correct
13 Correct 16 ms 4608 KB Output is correct
14 Correct 13 ms 4608 KB Output is correct
15 Correct 14 ms 4608 KB Output is correct
16 Correct 14 ms 4608 KB Output is correct
17 Correct 13 ms 4608 KB Output is correct
18 Correct 14 ms 4608 KB Output is correct
19 Correct 15 ms 4608 KB Output is correct
20 Correct 13 ms 4608 KB Output is correct
21 Correct 15 ms 4608 KB Output is correct
22 Correct 15 ms 4608 KB Output is correct
23 Correct 16 ms 4608 KB Output is correct
24 Correct 14 ms 4608 KB Output is correct
25 Correct 15 ms 4608 KB Output is correct
26 Correct 20 ms 4608 KB Output is correct
27 Correct 18 ms 4608 KB Output is correct
28 Correct 20 ms 4608 KB Output is correct
29 Correct 25 ms 4636 KB Output is correct
30 Correct 20 ms 4636 KB Output is correct
31 Correct 23 ms 4636 KB Output is correct
32 Correct 23 ms 4636 KB Output is correct
33 Correct 20 ms 4636 KB Output is correct
34 Correct 20 ms 4636 KB Output is correct
35 Correct 28 ms 4636 KB Output is correct
36 Correct 44 ms 4636 KB Output is correct
37 Correct 72 ms 4636 KB Output is correct
38 Correct 64 ms 4636 KB Output is correct
39 Correct 88 ms 4636 KB Output is correct
40 Correct 76 ms 4636 KB Output is correct
41 Correct 70 ms 4636 KB Output is correct
42 Correct 67 ms 4636 KB Output is correct
43 Correct 26 ms 4636 KB Output is correct
44 Correct 39 ms 4636 KB Output is correct
45 Correct 49 ms 4636 KB Output is correct
46 Correct 59 ms 4636 KB Output is correct
47 Correct 66 ms 4636 KB Output is correct
48 Correct 77 ms 4636 KB Output is correct
49 Correct 62 ms 4636 KB Output is correct
50 Correct 62 ms 4636 KB Output is correct
51 Correct 3 ms 4636 KB Output is correct
52 Correct 29 ms 4636 KB Output is correct
53 Correct 57 ms 4636 KB Output is correct
54 Correct 89 ms 4636 KB Output is correct
55 Correct 72 ms 4636 KB Output is correct
56 Correct 361 ms 11356 KB Output is correct
57 Correct 339 ms 11440 KB Output is correct
58 Correct 224 ms 11440 KB Output is correct
59 Correct 338 ms 11440 KB Output is correct
60 Correct 306 ms 11440 KB Output is correct
61 Correct 4 ms 11440 KB Output is correct
62 Correct 40 ms 11440 KB Output is correct
63 Correct 99 ms 11440 KB Output is correct
64 Correct 67 ms 11440 KB Output is correct
65 Correct 145 ms 11440 KB Output is correct
66 Correct 258 ms 11440 KB Output is correct
67 Correct 287 ms 11592 KB Output is correct
68 Correct 308 ms 11612 KB Output is correct
69 Correct 258 ms 11632 KB Output is correct