답안 #45923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45923 2018-04-16T13:37:48 Z antimirage Bali Sculptures (APIO15_sculpture) C++17
71 / 100
99 ms 768 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 = 105;

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];
         ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 496 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 2 ms 516 KB Output is correct
10 Correct 2 ms 516 KB Output is correct
11 Correct 2 ms 516 KB Output is correct
12 Correct 3 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Correct 2 ms 564 KB Output is correct
15 Correct 2 ms 564 KB Output is correct
16 Correct 2 ms 564 KB Output is correct
17 Correct 2 ms 564 KB Output is correct
18 Correct 2 ms 564 KB Output is correct
19 Correct 2 ms 564 KB Output is correct
20 Correct 2 ms 564 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 2 ms 620 KB Output is correct
24 Correct 2 ms 620 KB Output is correct
25 Correct 3 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 3 ms 636 KB Output is correct
31 Correct 3 ms 636 KB Output is correct
32 Correct 2 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 2 ms 636 KB Output is correct
35 Correct 3 ms 636 KB Output is correct
36 Correct 3 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 3 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 3 ms 636 KB Output is correct
27 Correct 3 ms 636 KB Output is correct
28 Correct 4 ms 636 KB Output is correct
29 Correct 5 ms 636 KB Output is correct
30 Correct 6 ms 636 KB Output is correct
31 Correct 8 ms 636 KB Output is correct
32 Correct 8 ms 636 KB Output is correct
33 Correct 10 ms 636 KB Output is correct
34 Correct 8 ms 636 KB Output is correct
35 Correct 9 ms 636 KB Output is correct
36 Correct 9 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 3 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 3 ms 636 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 3 ms 636 KB Output is correct
16 Correct 6 ms 636 KB Output is correct
17 Correct 8 ms 636 KB Output is correct
18 Correct 9 ms 636 KB Output is correct
19 Correct 8 ms 636 KB Output is correct
20 Correct 8 ms 636 KB Output is correct
21 Correct 8 ms 636 KB Output is correct
22 Correct 8 ms 636 KB Output is correct
23 Correct 10 ms 636 KB Output is correct
24 Correct 9 ms 636 KB Output is correct
25 Correct 16 ms 636 KB Output is correct
26 Correct 26 ms 636 KB Output is correct
27 Correct 49 ms 636 KB Output is correct
28 Correct 77 ms 636 KB Output is correct
29 Correct 86 ms 636 KB Output is correct
30 Correct 61 ms 636 KB Output is correct
31 Correct 55 ms 636 KB Output is correct
32 Correct 62 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 3 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 3 ms 636 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 2 ms 640 KB Output is correct
17 Correct 2 ms 640 KB Output is correct
18 Correct 2 ms 640 KB Output is correct
19 Correct 2 ms 640 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 3 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 640 KB Output is correct
30 Correct 2 ms 640 KB Output is correct
31 Correct 2 ms 640 KB Output is correct
32 Correct 2 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 2 ms 640 KB Output is correct
35 Correct 2 ms 640 KB Output is correct
36 Correct 3 ms 640 KB Output is correct
37 Correct 2 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 5 ms 640 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 10 ms 640 KB Output is correct
42 Correct 9 ms 640 KB Output is correct
43 Correct 10 ms 640 KB Output is correct
44 Correct 9 ms 640 KB Output is correct
45 Correct 14 ms 760 KB Output is correct
46 Correct 9 ms 760 KB Output is correct
47 Correct 9 ms 760 KB Output is correct
48 Correct 17 ms 760 KB Output is correct
49 Correct 27 ms 760 KB Output is correct
50 Correct 43 ms 760 KB Output is correct
51 Correct 66 ms 760 KB Output is correct
52 Correct 57 ms 760 KB Output is correct
53 Correct 62 ms 760 KB Output is correct
54 Correct 99 ms 760 KB Output is correct
55 Correct 61 ms 760 KB Output is correct
56 Correct 12 ms 760 KB Output is correct
57 Correct 29 ms 760 KB Output is correct
58 Correct 51 ms 760 KB Output is correct
59 Correct 79 ms 760 KB Output is correct
60 Correct 47 ms 760 KB Output is correct
61 Correct 47 ms 760 KB Output is correct
62 Correct 64 ms 760 KB Output is correct
63 Correct 52 ms 760 KB Output is correct
64 Correct 45 ms 760 KB Output is correct
65 Correct 9 ms 760 KB Output is correct
66 Correct 21 ms 760 KB Output is correct
67 Correct 26 ms 760 KB Output is correct
68 Correct 54 ms 760 KB Output is correct
69 Correct 51 ms 760 KB Output is correct
70 Correct 55 ms 760 KB Output is correct
71 Correct 53 ms 760 KB Output is correct
72 Correct 51 ms 760 KB Output is correct
73 Correct 49 ms 760 KB Output is correct
74 Correct 54 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 3 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 2 ms 760 KB Output is correct
22 Correct 3 ms 760 KB Output is correct
23 Correct 3 ms 760 KB Output is correct
24 Correct 3 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 7 ms 760 KB Output is correct
27 Correct 8 ms 760 KB Output is correct
28 Correct 12 ms 760 KB Output is correct
29 Correct 12 ms 760 KB Output is correct
30 Correct 9 ms 760 KB Output is correct
31 Correct 10 ms 760 KB Output is correct
32 Correct 9 ms 760 KB Output is correct
33 Correct 8 ms 760 KB Output is correct
34 Correct 9 ms 760 KB Output is correct
35 Correct 22 ms 760 KB Output is correct
36 Correct 36 ms 760 KB Output is correct
37 Correct 42 ms 760 KB Output is correct
38 Correct 58 ms 760 KB Output is correct
39 Correct 67 ms 760 KB Output is correct
40 Correct 57 ms 760 KB Output is correct
41 Correct 55 ms 760 KB Output is correct
42 Correct 55 ms 760 KB Output is correct
43 Correct 10 ms 760 KB Output is correct
44 Correct 25 ms 760 KB Output is correct
45 Correct 37 ms 760 KB Output is correct
46 Correct 54 ms 760 KB Output is correct
47 Correct 46 ms 760 KB Output is correct
48 Correct 47 ms 760 KB Output is correct
49 Correct 49 ms 760 KB Output is correct
50 Correct 49 ms 760 KB Output is correct
51 Correct 3 ms 760 KB Output is correct
52 Runtime error 16 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Halted 0 ms 0 KB -