Submission #739512

# Submission time Handle Problem Language Result Execution time Memory
739512 2023-05-10T14:44:37 Z Username4132 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
192 ms 14176 KB
#include<iostream>
#include<vector>
#include<random>
#include<algorithm>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define dforn(i, n) for(int i=n-1; i>=0; --i)

const int MAXN=2010, INF=1000000000;
int n, A, B, arr[MAXN], jump[MAXN][MAXN], dp1[MAXN];
bool dp2[102][102];

bool test(ll bit){
    forn(i, n){
        ll sum=0;
        forsn(j, i+1, n+1){
            sum+=arr[j-1];
            jump[i][j]=((sum|bit)==bit);
        }
    }
    if(A==1){
        dp1[n]=0;
        dforn(i, n){
            dp1[i]=INF;
            forsn(j, i+1, n+1) if(jump[i][j]) dp1[i]=min(dp1[i], dp1[j]+1);
        }
        return dp1[0]<=B;
    }
    else{
        forn(i, B+1) dp2[n][i]=false;
        forn(i, n) dp2[i][0]=false;
        dp2[n][0]=true;
        dforn(i, n) forsn(j, 1, B+1){
            dp2[i][j]=false;
            forsn(k, i+1, n+1) if(jump[i][k]) dp2[i][j]|=dp2[k][j-1];
        }
        bool ans=false;
        forsn(i, A, B+1) ans|=dp2[0][i];
        return ans;
    }
}

int main(){
    scanf("%d %d %d", &n, &A, &B);
    bool allzero=true;
    forn(i, n) scanf("%d", &arr[i]), allzero&=(!arr[i]);
    if(allzero){
        cout << "0\n";
        return 0;
    }
    ll lo=0, hi=(1LL<<42)-1;
    while(hi-lo>1){
        ll mid=(hi+lo)>>1;
        if(test(mid)) hi=mid;
        else lo=mid;
    }
    cout << hi << "\n";
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d %d %d", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:48:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     forn(i, n) scanf("%d", &arr[i]), allzero&=(!arr[i]);
      |                ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 456 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 304 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 308 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 436 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 432 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 432 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 2 ms 696 KB Output is correct
53 Correct 2 ms 724 KB Output is correct
54 Correct 2 ms 724 KB Output is correct
55 Correct 2 ms 724 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 1 ms 596 KB Output is correct
59 Correct 1 ms 664 KB Output is correct
60 Correct 1 ms 724 KB Output is correct
61 Correct 1 ms 724 KB Output is correct
62 Correct 1 ms 724 KB Output is correct
63 Correct 1 ms 724 KB Output is correct
64 Correct 27 ms 596 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 2 ms 524 KB Output is correct
67 Correct 4 ms 596 KB Output is correct
68 Correct 12 ms 692 KB Output is correct
69 Correct 23 ms 720 KB Output is correct
70 Correct 23 ms 724 KB Output is correct
71 Correct 1 ms 724 KB Output is correct
72 Correct 25 ms 724 KB Output is correct
73 Correct 19 ms 740 KB Output is correct
74 Correct 18 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 476 KB Output is correct
28 Correct 1 ms 476 KB Output is correct
29 Correct 1 ms 480 KB Output is correct
30 Correct 1 ms 480 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 480 KB Output is correct
33 Correct 1 ms 480 KB Output is correct
34 Correct 1 ms 480 KB Output is correct
35 Correct 1 ms 480 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 736 KB Output is correct
39 Correct 2 ms 736 KB Output is correct
40 Correct 1 ms 736 KB Output is correct
41 Correct 2 ms 752 KB Output is correct
42 Correct 1 ms 736 KB Output is correct
43 Correct 1 ms 480 KB Output is correct
44 Correct 1 ms 608 KB Output is correct
45 Correct 1 ms 608 KB Output is correct
46 Correct 1 ms 736 KB Output is correct
47 Correct 1 ms 736 KB Output is correct
48 Correct 1 ms 736 KB Output is correct
49 Correct 2 ms 736 KB Output is correct
50 Correct 1 ms 736 KB Output is correct
51 Correct 1 ms 736 KB Output is correct
52 Correct 18 ms 3168 KB Output is correct
53 Correct 26 ms 4320 KB Output is correct
54 Correct 48 ms 6260 KB Output is correct
55 Correct 49 ms 6228 KB Output is correct
56 Correct 181 ms 14152 KB Output is correct
57 Correct 184 ms 14140 KB Output is correct
58 Correct 182 ms 14036 KB Output is correct
59 Correct 174 ms 14152 KB Output is correct
60 Correct 189 ms 14132 KB Output is correct
61 Correct 2 ms 724 KB Output is correct
62 Correct 26 ms 4416 KB Output is correct
63 Correct 46 ms 6228 KB Output is correct
64 Correct 45 ms 6228 KB Output is correct
65 Correct 90 ms 9428 KB Output is correct
66 Correct 142 ms 12148 KB Output is correct
67 Correct 192 ms 14176 KB Output is correct
68 Correct 184 ms 14148 KB Output is correct
69 Correct 188 ms 14152 KB Output is correct