Submission #407015

# Submission time Handle Problem Language Result Execution time Memory
407015 2021-05-18T10:49:54 Z tranxuanbach Bali Sculptures (APIO15_sculpture) C++17
100 / 100
103 ms 532 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 2e3 + 5;

int n, L, R;
ll a[N];

ll ans;
bool dp1[N][N];
int dp2[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("KEK.inp", "r", stdin);
    // freopen("KEK.out", "w", stdout);
    cin >> n >> L >> R;
    ForE(i, 1, n){
        cin >> a[i]; a[i] += a[i - 1];
    }
    if (n <= 100){
        FordE(bit, 36, 0){
            ll tans = ans + (1ll << bit) - 1;
            ForE(i, 1, n){
                ForE(j, 1, R){
                    dp1[i][j] = 0;
                }
            }
            dp1[0][0] = 1;
            ForE(i, 1, n){
                ForE(j, 1, R){
                    ForE(ti, 1, i){
                        ll sum = a[i] - a[ti - 1];
                        if ((tans & sum) == sum){
                            dp1[i][j] |= dp1[ti - 1][j - 1];
                        }
                    }
                }
            }
            bool ck = 0;
            ForE(j, L, R){
                ck |= dp1[n][j];
            }
            if (!ck){
                ans |= (1ll << bit);
            }
        }
        cout << ans << endl;
        return 0;
    }
    assert(L == 1);
    FordE(bit, 40, 0){
        ll tans = ans + (1ll << bit) - 1;
        ForE(i, 1, n){
            dp2[i] = N;
        }
        dp2[0] = 0;
        ForE(i, 1, n){
            ForE(ti, 1, i){
                ll sum = a[i] - a[ti - 1];
                if ((tans & sum) == sum){
                    dp2[i] = min(dp2[i], dp2[ti - 1] + 1);
                }
            }
        }
        if (dp2[n] > R){
            ans |= (1ll << bit);
        }
    }
    cout << ans << endl;
}

/*
n so, phan thanh x (a <= x <= b) khoang sao cho or cua tong la be nhat
nhieu kha nang sub 4 va sub 5 giai khac nhau vi sub 5 co a = 1 ????
xet bit cao nhat xong roi kiem tra xem co dat duoc tong do hay ko?
dp[i][j] = chekc xem phan duoc thanh j doan co or la submask cua X hay ko
update n^2?
n^3 * 30 la xong sub 1-4
a = 1 thi
xet xem so doan duoc phan it nhat la bao nhieu a
==================================================+
INPUT:                                            |
--------------------------------------------------|
6 1 3
8 1 2 1 5 4
--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|
11
--------------------------------------------------|
==================================================+
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 324 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 3 ms 324 KB Output is correct
35 Correct 3 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 432 KB Output is correct
19 Correct 3 ms 324 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 3 ms 332 KB Output is correct
25 Correct 3 ms 460 KB Output is correct
26 Correct 7 ms 460 KB Output is correct
27 Correct 20 ms 460 KB Output is correct
28 Correct 46 ms 460 KB Output is correct
29 Correct 43 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 23 ms 528 KB Output is correct
32 Correct 32 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 3 ms 332 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 328 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 7 ms 460 KB Output is correct
50 Correct 20 ms 512 KB Output is correct
51 Correct 45 ms 452 KB Output is correct
52 Correct 44 ms 524 KB Output is correct
53 Correct 2 ms 460 KB Output is correct
54 Correct 22 ms 532 KB Output is correct
55 Correct 33 ms 460 KB Output is correct
56 Correct 3 ms 332 KB Output is correct
57 Correct 6 ms 460 KB Output is correct
58 Correct 16 ms 516 KB Output is correct
59 Correct 34 ms 460 KB Output is correct
60 Correct 34 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 35 ms 460 KB Output is correct
63 Correct 36 ms 460 KB Output is correct
64 Correct 32 ms 460 KB Output is correct
65 Correct 3 ms 332 KB Output is correct
66 Correct 3 ms 332 KB Output is correct
67 Correct 6 ms 460 KB Output is correct
68 Correct 18 ms 512 KB Output is correct
69 Correct 34 ms 460 KB Output is correct
70 Correct 41 ms 516 KB Output is correct
71 Correct 2 ms 460 KB Output is correct
72 Correct 36 ms 460 KB Output is correct
73 Correct 26 ms 532 KB Output is correct
74 Correct 23 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 3 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 3 ms 320 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 3 ms 332 KB Output is correct
35 Correct 3 ms 332 KB Output is correct
36 Correct 7 ms 460 KB Output is correct
37 Correct 21 ms 508 KB Output is correct
38 Correct 43 ms 524 KB Output is correct
39 Correct 47 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 21 ms 532 KB Output is correct
42 Correct 34 ms 460 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 6 ms 460 KB Output is correct
45 Correct 17 ms 512 KB Output is correct
46 Correct 34 ms 460 KB Output is correct
47 Correct 33 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 35 ms 460 KB Output is correct
50 Correct 35 ms 528 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 10 ms 324 KB Output is correct
53 Correct 16 ms 344 KB Output is correct
54 Correct 29 ms 340 KB Output is correct
55 Correct 30 ms 348 KB Output is correct
56 Correct 96 ms 332 KB Output is correct
57 Correct 96 ms 332 KB Output is correct
58 Correct 90 ms 360 KB Output is correct
59 Correct 89 ms 332 KB Output is correct
60 Correct 103 ms 336 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 16 ms 332 KB Output is correct
63 Correct 29 ms 332 KB Output is correct
64 Correct 26 ms 328 KB Output is correct
65 Correct 49 ms 332 KB Output is correct
66 Correct 72 ms 332 KB Output is correct
67 Correct 96 ms 332 KB Output is correct
68 Correct 101 ms 348 KB Output is correct
69 Correct 94 ms 332 KB Output is correct