Submission #238966

# Submission time Handle Problem Language Result Execution time Memory
238966 2020-06-13T19:31:18 Z aggu_01000101 Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 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){
    for(int i = lat;i<=40;i++){
        if(((ans&pow2[i])==0) && ((curr&pow2[i])!=0)) 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 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 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 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 4 ms 384 KB Output is correct
15 Correct 4 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 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 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 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 4 ms 384 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 5 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 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 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 6 ms 384 KB Output is correct
36 Correct 6 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 384 KB Output is correct
7 Correct 6 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 5 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 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 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 6 ms 384 KB Output is correct
28 Correct 7 ms 384 KB Output is correct
29 Correct 7 ms 384 KB Output is correct
30 Correct 7 ms 384 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 7 ms 512 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 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 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 5 ms 384 KB Output is correct
16 Correct 5 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 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 6 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 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
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 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 6 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 6 ms 384 KB Output is correct
49 Correct 6 ms 384 KB Output is correct
50 Correct 6 ms 384 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 8 ms 384 KB Output is correct
54 Correct 7 ms 384 KB Output is correct
55 Correct 7 ms 384 KB Output is correct
56 Correct 6 ms 384 KB Output is correct
57 Correct 7 ms 384 KB Output is correct
58 Correct 8 ms 384 KB Output is correct
59 Correct 9 ms 384 KB Output is correct
60 Correct 8 ms 384 KB Output is correct
61 Correct 6 ms 384 KB Output is correct
62 Correct 7 ms 384 KB Output is correct
63 Correct 7 ms 384 KB Output is correct
64 Correct 22 ms 384 KB Output is correct
65 Correct 7 ms 384 KB Output is correct
66 Correct 8 ms 384 KB Output is correct
67 Correct 9 ms 384 KB Output is correct
68 Correct 11 ms 384 KB Output is correct
69 Correct 12 ms 384 KB Output is correct
70 Correct 12 ms 384 KB Output is correct
71 Correct 11 ms 384 KB Output is correct
72 Correct 14 ms 384 KB Output is correct
73 Correct 14 ms 384 KB Output is correct
74 Correct 14 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 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 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 4 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 5 ms 384 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 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 428 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 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 6 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 7 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 7 ms 384 KB Output is correct
39 Correct 7 ms 384 KB Output is correct
40 Correct 7 ms 384 KB Output is correct
41 Correct 7 ms 384 KB Output is correct
42 Correct 7 ms 384 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 7 ms 384 KB Output is correct
45 Correct 8 ms 384 KB Output is correct
46 Correct 8 ms 384 KB Output is correct
47 Correct 6 ms 384 KB Output is correct
48 Correct 6 ms 384 KB Output is correct
49 Correct 7 ms 384 KB Output is correct
50 Correct 7 ms 256 KB Output is correct
51 Correct 8 ms 384 KB Output is correct
52 Correct 117 ms 504 KB Output is correct
53 Correct 206 ms 384 KB Output is correct
54 Correct 305 ms 504 KB Output is correct
55 Correct 354 ms 504 KB Output is correct
56 Execution timed out 1089 ms 384 KB Time limit exceeded
57 Halted 0 ms 0 KB -