Submission #238967

# Submission time Handle Problem Language Result Execution time Memory
238967 2020-06-13T19:35:44 Z aggu_01000101 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
128 ms 512 KB
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
int n, a, b;
int arr[2005];
int pow2[45];
bool check(int ans, int lat, int curr){
    //find overlap of first (lat - 1) powers
    int temp = ans|curr;
    int diff = temp - ans;
    //sum of first (lat - 1) powers = 2^lat - 1
    if(diff > (pow2[lat] - 1)) return false;
    return true;
}
bool dp(int ans, int lat){ //o(n^2)
    int dp[n+1]; //minimum number of partitions required
    dp[0] = 0;
    for(int i = 1;i<=n;i++){
        dp[i] = INF;
        int sum = 0;
        for(int j = i;j>=1;j--){
            sum+=arr[j];
            if(check(ans, lat, sum)) dp[i] = min(dp[i], dp[j-1] + 1);
        }
        //cout<<"dp["<<i<<"] = "<<dp[i]<<" for ans = "<<ans<<" and lat = "<<lat<<"\n";
    }
    if(dp[n]<=b) return true;
    return false;
}
int dp1(int ans, int lat){//o(n^3)
    bool dp[n+1][n+1]; //whether it's possible
    for(int i = 0;i<=n;i++) dp[0][i] = false;
    dp[0][0] = true;
    for(int i = 1;i<=n;i++){
        for(int k = 0;k<=n;k++){
            dp[i][k] = false;
        }
        int sum = 0;
        for(int j = i;j>=1;j--){
            sum+=arr[j];
            if(check(ans, lat, sum)){
                for(int k = 1;k<=n;k++){
                    if(dp[j-1][k-1]) dp[i][k] = true;
                }
            }
        }
    }
    bool found = false;
    for(int i = a;i<=b;i++) found = found || dp[n][i];
    return found;
}
bool f(int ans, int lat){ //o(n^3)
    if(a==1){
        return dp(ans, lat);
    }
    else{
        return dp1(ans, lat);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>a>>b;
    for(int i = 1;i<=n;i++) cin>>arr[i];
    pow2[0] = 1;
    for(int i = 1;i<45;i++) pow2[i] = pow2[i-1]*2;
    int ans = 0;
    for(int i = 40;i>=0;i--){
        bool can = f(ans, i);
        //cout<<i<<" "<<can<<"\n";
        if(!can) ans+=pow2[i];
    }
    cout<<ans<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 416 KB Output is correct
17 Correct 5 ms 416 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 360 KB Output is correct
24 Correct 6 ms 360 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 8 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 288 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 4 ms 384 KB Output is correct
38 Correct 4 ms 288 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 6 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 9 ms 512 KB Output is correct
63 Correct 5 ms 384 KB Output is correct
64 Correct 19 ms 384 KB Output is correct
65 Correct 5 ms 384 KB Output is correct
66 Correct 6 ms 384 KB Output is correct
67 Correct 9 ms 384 KB Output is correct
68 Correct 8 ms 384 KB Output is correct
69 Correct 9 ms 384 KB Output is correct
70 Correct 8 ms 384 KB Output is correct
71 Correct 9 ms 384 KB Output is correct
72 Correct 11 ms 384 KB Output is correct
73 Correct 11 ms 384 KB Output is correct
74 Correct 11 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 6 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 6 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 5 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 288 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 15 ms 384 KB Output is correct
53 Correct 22 ms 384 KB Output is correct
54 Correct 38 ms 384 KB Output is correct
55 Correct 38 ms 384 KB Output is correct
56 Correct 128 ms 384 KB Output is correct
57 Correct 120 ms 504 KB Output is correct
58 Correct 119 ms 384 KB Output is correct
59 Correct 110 ms 384 KB Output is correct
60 Correct 128 ms 504 KB Output is correct
61 Correct 5 ms 384 KB Output is correct
62 Correct 23 ms 384 KB Output is correct
63 Correct 39 ms 384 KB Output is correct
64 Correct 36 ms 384 KB Output is correct
65 Correct 64 ms 384 KB Output is correct
66 Correct 91 ms 504 KB Output is correct
67 Correct 128 ms 384 KB Output is correct
68 Correct 121 ms 384 KB Output is correct
69 Correct 122 ms 384 KB Output is correct