답안 #70658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70658 2018-08-23T08:17:16 Z evpipis Bali Sculptures (APIO15_sculpture) C++11
100 / 100
112 ms 1176 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int inf = 1e9;
int dp1[105][105], dp2[2005], n, a, b, arr[2005];

bool solve1(ll x){
    dp1[n+1][0] = 1;
    for (int i = n; i >= 1; i--)
        for (int k = 1; k <= b; k++){
            ll sum = 0;
            dp1[i][k] = 0;
            for (int j = i; j <= n; j++){
                sum += arr[j];
                if ((sum|x) == x)
                    dp1[i][k] |= dp1[j+1][k-1];
            }
        }

    for (int k = a; k <= b; k++)
        if (dp1[1][k]) return true;
    return false;
}

bool solve2(ll x){
    for (int i = n; i >= 1; i--){
        ll sum = 0;
        dp2[i] = inf;
        for (int j = i; j <= n; j++){
            sum += arr[j];
            if ((sum|x) == x)
                dp2[i] = min(dp2[i], dp2[j+1]+1);
        }
    }

    return (dp2[1] <= b);
}

int main(){
    scanf("%d %d %d", &n, &a, &b);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);

    ll ans = (1LL<<41)-1;
    for (int j = 40; j >= 0; j--){
        if (a != 1 && solve1(ans^(1LL<<j)))
            ans ^= (1LL<<j);
        if (a == 1 && solve2(ans^(1LL<<j)))
            ans ^= (1LL<<j);
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 2 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 4 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 2 ms 544 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 4 ms 620 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 2 ms 624 KB Output is correct
24 Correct 3 ms 624 KB Output is correct
25 Correct 2 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 2 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
29 Correct 2 ms 624 KB Output is correct
30 Correct 2 ms 624 KB Output is correct
31 Correct 2 ms 624 KB Output is correct
32 Correct 2 ms 624 KB Output is correct
33 Correct 3 ms 624 KB Output is correct
34 Correct 3 ms 624 KB Output is correct
35 Correct 2 ms 624 KB Output is correct
36 Correct 2 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 624 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Correct 4 ms 624 KB Output is correct
4 Correct 3 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 624 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 3 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 2 ms 624 KB Output is correct
19 Correct 3 ms 624 KB Output is correct
20 Correct 3 ms 624 KB Output is correct
21 Correct 3 ms 624 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 3 ms 624 KB Output is correct
24 Correct 2 ms 624 KB Output is correct
25 Correct 3 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 3 ms 624 KB Output is correct
28 Correct 2 ms 624 KB Output is correct
29 Correct 3 ms 624 KB Output is correct
30 Correct 3 ms 624 KB Output is correct
31 Correct 3 ms 624 KB Output is correct
32 Correct 3 ms 624 KB Output is correct
33 Correct 3 ms 624 KB Output is correct
34 Correct 2 ms 624 KB Output is correct
35 Correct 3 ms 624 KB Output is correct
36 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 624 KB Output is correct
2 Correct 2 ms 624 KB Output is correct
3 Correct 2 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 2 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 2 ms 624 KB Output is correct
14 Correct 2 ms 624 KB Output is correct
15 Correct 3 ms 624 KB Output is correct
16 Correct 2 ms 624 KB Output is correct
17 Correct 2 ms 624 KB Output is correct
18 Correct 3 ms 624 KB Output is correct
19 Correct 3 ms 624 KB Output is correct
20 Correct 3 ms 624 KB Output is correct
21 Correct 3 ms 624 KB Output is correct
22 Correct 3 ms 624 KB Output is correct
23 Correct 2 ms 624 KB Output is correct
24 Correct 2 ms 624 KB Output is correct
25 Correct 3 ms 624 KB Output is correct
26 Correct 2 ms 624 KB Output is correct
27 Correct 3 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
29 Correct 3 ms 624 KB Output is correct
30 Correct 3 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 4 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 628 KB Output is correct
2 Correct 3 ms 628 KB Output is correct
3 Correct 3 ms 628 KB Output is correct
4 Correct 3 ms 628 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 3 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 4 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 3 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 3 ms 628 KB Output is correct
19 Correct 3 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 2 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 3 ms 628 KB Output is correct
24 Correct 3 ms 628 KB Output is correct
25 Correct 3 ms 628 KB Output is correct
26 Correct 2 ms 628 KB Output is correct
27 Correct 2 ms 628 KB Output is correct
28 Correct 2 ms 628 KB Output is correct
29 Correct 2 ms 628 KB Output is correct
30 Correct 2 ms 628 KB Output is correct
31 Correct 2 ms 628 KB Output is correct
32 Correct 4 ms 628 KB Output is correct
33 Correct 2 ms 628 KB Output is correct
34 Correct 2 ms 628 KB Output is correct
35 Correct 2 ms 628 KB Output is correct
36 Correct 3 ms 628 KB Output is correct
37 Correct 2 ms 628 KB Output is correct
38 Correct 2 ms 628 KB Output is correct
39 Correct 2 ms 628 KB Output is correct
40 Correct 2 ms 628 KB Output is correct
41 Correct 2 ms 628 KB Output is correct
42 Correct 3 ms 628 KB Output is correct
43 Correct 3 ms 628 KB Output is correct
44 Correct 3 ms 628 KB Output is correct
45 Correct 2 ms 628 KB Output is correct
46 Correct 3 ms 628 KB Output is correct
47 Correct 3 ms 628 KB Output is correct
48 Correct 3 ms 628 KB Output is correct
49 Correct 3 ms 628 KB Output is correct
50 Correct 2 ms 628 KB Output is correct
51 Correct 2 ms 628 KB Output is correct
52 Correct 3 ms 628 KB Output is correct
53 Correct 3 ms 628 KB Output is correct
54 Correct 3 ms 628 KB Output is correct
55 Correct 3 ms 628 KB Output is correct
56 Correct 2 ms 628 KB Output is correct
57 Correct 2 ms 628 KB Output is correct
58 Correct 3 ms 628 KB Output is correct
59 Correct 3 ms 628 KB Output is correct
60 Correct 3 ms 628 KB Output is correct
61 Correct 3 ms 628 KB Output is correct
62 Correct 3 ms 628 KB Output is correct
63 Correct 3 ms 628 KB Output is correct
64 Correct 35 ms 636 KB Output is correct
65 Correct 6 ms 636 KB Output is correct
66 Correct 5 ms 636 KB Output is correct
67 Correct 10 ms 636 KB Output is correct
68 Correct 19 ms 636 KB Output is correct
69 Correct 33 ms 636 KB Output is correct
70 Correct 51 ms 636 KB Output is correct
71 Correct 4 ms 636 KB Output is correct
72 Correct 41 ms 640 KB Output is correct
73 Correct 29 ms 640 KB Output is correct
74 Correct 24 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 2 ms 640 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 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 3 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 640 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 640 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 3 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 4 ms 640 KB Output is correct
36 Correct 3 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 3 ms 640 KB Output is correct
46 Correct 3 ms 640 KB Output is correct
47 Correct 3 ms 640 KB Output is correct
48 Correct 3 ms 640 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 3 ms 640 KB Output is correct
52 Correct 12 ms 640 KB Output is correct
53 Correct 17 ms 768 KB Output is correct
54 Correct 40 ms 768 KB Output is correct
55 Correct 27 ms 768 KB Output is correct
56 Correct 97 ms 784 KB Output is correct
57 Correct 102 ms 912 KB Output is correct
58 Correct 102 ms 912 KB Output is correct
59 Correct 89 ms 1016 KB Output is correct
60 Correct 98 ms 1016 KB Output is correct
61 Correct 3 ms 1016 KB Output is correct
62 Correct 17 ms 1016 KB Output is correct
63 Correct 30 ms 1016 KB Output is correct
64 Correct 40 ms 1016 KB Output is correct
65 Correct 56 ms 1016 KB Output is correct
66 Correct 71 ms 1016 KB Output is correct
67 Correct 94 ms 1016 KB Output is correct
68 Correct 112 ms 1172 KB Output is correct
69 Correct 108 ms 1176 KB Output is correct