답안 #1073911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073911 2024-08-25T03:01:49 Z ngrace Bali Sculptures (APIO15_sculpture) C++14
100 / 100
95 ms 1236 KB
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define on(i,mask) ((bool)((1<<(i)) & (mask)))

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    v<ll> Y(N+1,0);
    v<ll> psum(N+1, 0);
    ll maxY = 0;
    for(int i=1; i<=N; i++){
        cin>>Y[i];
        maxY = max(maxY, Y[i]);
        psum[i] = psum[i-1]+Y[i];
    }

    if(N<=20){//sub1
        ll ans = 1e18;
        for(int div = (1<<N); div<(1<<(N+1)); div++){
            int g = 1;
            int l=0;
            ll res = 0;
            for(int i=1; i<=N; i++){
                if(i!=1 && on(i-2,div)!=on(i-1,div)){
                    g++;
                    res = res | (psum[i-1] - psum[l]);
                    l=i-1;
                }
            }
            res = res | (psum[N]-psum[l]);

            if(A<=g && g<=B) ans = min(ans, res);
        }
        cout<<ans<<endl;
    }
    else if(N<=50 && B<=20 && maxY<=10){//sub2
        v<v<v<bool>>> dp(B+1, v<v<bool>>(N+1, v<bool>(maxY*N+1, false)));
        dp[0][0][0] = true;
        for(int b=0; b<B; b++){
            for(int n=0; n<=N; n++){
                for(int o=0;o<=maxY*N;o++){
                    if(dp[b][n][o]){//can cover first n in b groups with or sum o
                        for(int i=n+1; i<=N; i++){
                            dp[b+1][i][o | (psum[i]-psum[n])] = true;
                        }
                    }
                }
            }
        }

        int ans = maxY*N;
        for(int b=A; b<=B; b++){
            for(int o=0; o<=ans; o++){
                if(dp[b][N][o]){
                    ans=o;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    else if(N<=100 && A==1 && maxY<=20){//sub3
        v<v<int>> dp(N+1, v<int>(maxY*N+1, 1e9));
        dp[0][0] = 0;
        for(int n=0; n<=N; n++){
            for(int o=0;o<=maxY*N;o++){
                if(dp[n][o] !=1e9){//min groups to cover first n with or sum o
                    for(int i=n+1; i<=N; i++){
                        dp[i][o | (psum[i]-psum[n])] = min(dp[i][o | (psum[i]-psum[n])], dp[n][o]+1);
                    }
                }
            }
        }

        int ans = maxY*N;
        for(int o=0; o<=ans; o++){
            if(dp[N][o]<=B){
                ans=o;
                break;
            }
        }
        cout<<ans<<endl;
    }
    else if(N<=100){//sub4
        ll is0 = 0;
        for(int bit=40; bit>=0; bit--){
            v<v<bool>> dp(B+1, v<bool>(N+1, false));
            ll test = is0 | (1ll<<bit);
            dp[0][0] = true;
            for(int b=0; b<B; b++){
                for(int n=0; n<=N; n++){
                    if(dp[b][n]){//can cover first n in b groups while keeping all on bits in is0 zero.
                        for(int i=n+1; i<=N; i++){
                            ll s = psum[i] - psum[n];
                            if((s & test) == 0) dp[b+1][i] = true;
                        }
                    }
                }
            }

            for(int b=A; b<=B; b++){
                if(dp[b][N]){
                    is0 |= (1ll<<bit);
                    break;
                }
            }
        }
        cout<<((1ll<<41) - is0 - 1)<<endl;
    }
    else if(N<=2000 && A==1){//sub 5
        ll is0 = 0;
        for(int bit=60; bit>=0; bit--){
            v<int> dp(N+1, 1e9);
            ll test = is0 | (1ll<<bit);
            dp[0] = 0;
            for(int n=0; n<=N; n++){
                if(dp[n] != 1e9){//min groups to cover first n while keeping all on bits in is0 zero.
                    for(int i=n+1; i<=N; i++){
                        ll s = psum[i] - psum[n];
                        if((s & test) == 0) dp[i] = min(dp[i], dp[n]+1);
                    }
                }
            }

            if(dp[N]<=B){
                is0 |= (1ll<<bit);
            }
        }
        cout<<((1ll<<61) - is0 - 1)<<endl;
    }
}
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 8 ms 432 KB Output is correct
8 Correct 71 ms 412 KB Output is correct
9 Correct 71 ms 348 KB Output is correct
10 Correct 71 ms 348 KB Output is correct
11 Correct 73 ms 348 KB Output is correct
12 Correct 74 ms 404 KB Output is correct
13 Correct 73 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 9 ms 348 KB Output is correct
21 Correct 67 ms 348 KB Output is correct
22 Correct 66 ms 348 KB Output is correct
23 Correct 66 ms 344 KB Output is correct
24 Correct 71 ms 344 KB Output is correct
25 Correct 67 ms 348 KB Output is correct
26 Correct 67 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 35 ms 404 KB Output is correct
31 Correct 69 ms 348 KB Output is correct
32 Correct 70 ms 344 KB Output is correct
33 Correct 68 ms 344 KB Output is correct
34 Correct 70 ms 408 KB Output is correct
35 Correct 71 ms 348 KB Output is correct
36 Correct 70 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 9 ms 348 KB Output is correct
8 Correct 72 ms 408 KB Output is correct
9 Correct 71 ms 412 KB Output is correct
10 Correct 72 ms 600 KB Output is correct
11 Correct 78 ms 344 KB Output is correct
12 Correct 79 ms 348 KB Output is correct
13 Correct 72 ms 408 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 9 ms 344 KB Output is correct
21 Correct 73 ms 412 KB Output is correct
22 Correct 67 ms 408 KB Output is correct
23 Correct 67 ms 344 KB Output is correct
24 Correct 71 ms 344 KB Output is correct
25 Correct 67 ms 348 KB Output is correct
26 Correct 75 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 416 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 8 ms 436 KB Output is correct
8 Correct 74 ms 424 KB Output is correct
9 Correct 71 ms 348 KB Output is correct
10 Correct 71 ms 344 KB Output is correct
11 Correct 71 ms 348 KB Output is correct
12 Correct 71 ms 344 KB Output is correct
13 Correct 71 ms 408 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 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1152 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 71 ms 348 KB Output is correct
9 Correct 79 ms 348 KB Output is correct
10 Correct 73 ms 348 KB Output is correct
11 Correct 71 ms 344 KB Output is correct
12 Correct 71 ms 348 KB Output is correct
13 Correct 71 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 8 ms 348 KB Output is correct
21 Correct 67 ms 344 KB Output is correct
22 Correct 67 ms 348 KB Output is correct
23 Correct 66 ms 348 KB Output is correct
24 Correct 71 ms 404 KB Output is correct
25 Correct 67 ms 344 KB Output is correct
26 Correct 67 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 35 ms 432 KB Output is correct
31 Correct 70 ms 408 KB Output is correct
32 Correct 71 ms 344 KB Output is correct
33 Correct 68 ms 408 KB Output is correct
34 Correct 70 ms 408 KB Output is correct
35 Correct 71 ms 344 KB Output is correct
36 Correct 71 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 1116 KB Output is correct
52 Correct 1 ms 1116 KB Output is correct
53 Correct 1 ms 1116 KB Output is correct
54 Correct 1 ms 1116 KB Output is correct
55 Correct 1 ms 1116 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 3 ms 348 KB Output is correct
60 Correct 5 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 4 ms 348 KB Output is correct
63 Correct 4 ms 348 KB Output is correct
64 Correct 7 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 3 ms 436 KB Output is correct
69 Correct 3 ms 348 KB Output is correct
70 Correct 3 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 4 ms 348 KB Output is correct
73 Correct 4 ms 348 KB Output is correct
74 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 8 ms 348 KB Output is correct
8 Correct 71 ms 348 KB Output is correct
9 Correct 71 ms 348 KB Output is correct
10 Correct 73 ms 348 KB Output is correct
11 Correct 80 ms 348 KB Output is correct
12 Correct 71 ms 344 KB Output is correct
13 Correct 71 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 35 ms 432 KB Output is correct
18 Correct 67 ms 348 KB Output is correct
19 Correct 72 ms 348 KB Output is correct
20 Correct 68 ms 412 KB Output is correct
21 Correct 70 ms 344 KB Output is correct
22 Correct 71 ms 348 KB Output is correct
23 Correct 70 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 1 ms 1236 KB Output is correct
39 Correct 1 ms 1116 KB Output is correct
40 Correct 1 ms 1116 KB Output is correct
41 Correct 2 ms 1116 KB Output is correct
42 Correct 1 ms 1116 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 4 ms 412 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 4 ms 440 KB Output is correct
50 Correct 4 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 6 ms 456 KB Output is correct
53 Correct 7 ms 348 KB Output is correct
54 Correct 23 ms 344 KB Output is correct
55 Correct 17 ms 344 KB Output is correct
56 Correct 47 ms 344 KB Output is correct
57 Correct 43 ms 344 KB Output is correct
58 Correct 53 ms 344 KB Output is correct
59 Correct 89 ms 480 KB Output is correct
60 Correct 50 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 7 ms 456 KB Output is correct
63 Correct 24 ms 348 KB Output is correct
64 Correct 11 ms 460 KB Output is correct
65 Correct 22 ms 348 KB Output is correct
66 Correct 34 ms 348 KB Output is correct
67 Correct 45 ms 348 KB Output is correct
68 Correct 95 ms 488 KB Output is correct
69 Correct 46 ms 344 KB Output is correct