#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
int n, l, r, a[MAXN];
int dp[MAXN], dp2[MAXN];
inline bool check(const ll &lim, const ll &mid, const ll &MOD, const ll &tmp) {
dp[0] = 0;
dp2[0] = 0;
rep(i, 1, n) {
ll cur = 0ll;
dp[i] = n+n;
dp2[i] = -(n+n);
per(j, i, 1) {
cur += a[j];
if(cur >= lim) break;
if((cur & tmp) == 0ll && cur % MOD < mid) {
updmin(dp[i], dp[j-1]+1);
updmax(dp2[i], dp2[j-1]+1);
}
}
}
return dp[n] <= r && dp2[n] >= l;
}
map < pair < ll, pair < ll, ll > >, ll > dd;
ll rec(int i, ll cost, int cnt) {
if(i == n+1) {
if(l <= cnt && cnt <= r) return cost;
return (ll)1e15;
}
if(dd.count(mp(i, mp(cost, cnt)))) return dd[mp(i, mp(cost, cnt))];
ll ans = (ll)1e15;
ll sum = 0;
rep(j, i, n) {
sum += a[j];
ans = min(ans, rec(j+1, cost | sum, cnt+1));
}
return dd[mp(i, mp(cost, cnt))] = ans;
}
int main() {
#ifdef accepted
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
onlycin;
cin >> n >> l >> r;
rep(i, 1, n) cin >> a[i];
if(l > 1 && n <= 50) {
cout << rec(1, 0, 0) << nxtl;
return 0;
}
int last = 42, fr = 42;
ll res = 0ll;
ll just = 0ll;
per(bit, 40, 0) {
ll lim = (1ll << fr*1ll);
if(last == 42) lim = (1ll << bit);
if(!check(lim, (1ll<<bit*1ll), (1ll << last*1ll), just)) {
if(fr == 42) fr = bit+1;
res |= (1ll << bit*1ll);
last = bit;
} else just |= (1ll << bit*1ll);
}
cout << res << nxtl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
404 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
548 KB |
Output is correct |
7 |
Correct |
2 ms |
548 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
652 KB |
Output is correct |
13 |
Correct |
2 ms |
652 KB |
Output is correct |
14 |
Correct |
2 ms |
652 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
3 ms |
732 KB |
Output is correct |
22 |
Correct |
2 ms |
732 KB |
Output is correct |
23 |
Correct |
2 ms |
732 KB |
Output is correct |
24 |
Correct |
3 ms |
732 KB |
Output is correct |
25 |
Correct |
2 ms |
732 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
2 ms |
732 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
29 |
Correct |
1 ms |
732 KB |
Output is correct |
30 |
Correct |
2 ms |
732 KB |
Output is correct |
31 |
Correct |
2 ms |
732 KB |
Output is correct |
32 |
Correct |
2 ms |
732 KB |
Output is correct |
33 |
Correct |
2 ms |
732 KB |
Output is correct |
34 |
Correct |
2 ms |
732 KB |
Output is correct |
35 |
Correct |
2 ms |
732 KB |
Output is correct |
36 |
Correct |
2 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
732 KB |
Output is correct |
2 |
Correct |
2 ms |
732 KB |
Output is correct |
3 |
Correct |
2 ms |
732 KB |
Output is correct |
4 |
Correct |
2 ms |
732 KB |
Output is correct |
5 |
Correct |
2 ms |
732 KB |
Output is correct |
6 |
Correct |
2 ms |
732 KB |
Output is correct |
7 |
Correct |
2 ms |
732 KB |
Output is correct |
8 |
Correct |
2 ms |
732 KB |
Output is correct |
9 |
Correct |
3 ms |
732 KB |
Output is correct |
10 |
Correct |
3 ms |
732 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
2 ms |
732 KB |
Output is correct |
13 |
Correct |
2 ms |
732 KB |
Output is correct |
14 |
Correct |
2 ms |
732 KB |
Output is correct |
15 |
Correct |
2 ms |
732 KB |
Output is correct |
16 |
Correct |
2 ms |
732 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
3 ms |
732 KB |
Output is correct |
22 |
Correct |
2 ms |
732 KB |
Output is correct |
23 |
Correct |
2 ms |
732 KB |
Output is correct |
24 |
Correct |
2 ms |
732 KB |
Output is correct |
25 |
Correct |
3 ms |
732 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
2 ms |
732 KB |
Output is correct |
28 |
Correct |
2 ms |
732 KB |
Output is correct |
29 |
Correct |
2 ms |
732 KB |
Output is correct |
30 |
Correct |
3 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
756 KB |
Output is correct |
32 |
Correct |
2 ms |
756 KB |
Output is correct |
33 |
Correct |
2 ms |
756 KB |
Output is correct |
34 |
Correct |
2 ms |
756 KB |
Output is correct |
35 |
Correct |
3 ms |
756 KB |
Output is correct |
36 |
Correct |
2 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
756 KB |
Output is correct |
2 |
Correct |
2 ms |
756 KB |
Output is correct |
3 |
Correct |
2 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
756 KB |
Output is correct |
7 |
Correct |
2 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
756 KB |
Output is correct |
9 |
Correct |
2 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
756 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
756 KB |
Output is correct |
13 |
Correct |
2 ms |
756 KB |
Output is correct |
14 |
Correct |
2 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
2 ms |
756 KB |
Output is correct |
17 |
Correct |
2 ms |
756 KB |
Output is correct |
18 |
Correct |
3 ms |
756 KB |
Output is correct |
19 |
Correct |
2 ms |
756 KB |
Output is correct |
20 |
Correct |
2 ms |
756 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
756 KB |
Output is correct |
23 |
Correct |
2 ms |
756 KB |
Output is correct |
24 |
Correct |
2 ms |
756 KB |
Output is correct |
25 |
Correct |
3 ms |
756 KB |
Output is correct |
26 |
Correct |
3 ms |
756 KB |
Output is correct |
27 |
Correct |
4 ms |
756 KB |
Output is correct |
28 |
Correct |
5 ms |
756 KB |
Output is correct |
29 |
Correct |
5 ms |
756 KB |
Output is correct |
30 |
Correct |
5 ms |
756 KB |
Output is correct |
31 |
Correct |
4 ms |
756 KB |
Output is correct |
32 |
Correct |
4 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
756 KB |
Output is correct |
2 |
Correct |
2 ms |
756 KB |
Output is correct |
3 |
Correct |
2 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
756 KB |
Output is correct |
7 |
Correct |
2 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
756 KB |
Output is correct |
9 |
Correct |
2 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
756 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
756 KB |
Output is correct |
13 |
Correct |
2 ms |
756 KB |
Output is correct |
14 |
Correct |
2 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
2 ms |
756 KB |
Output is correct |
17 |
Correct |
2 ms |
756 KB |
Output is correct |
18 |
Correct |
2 ms |
756 KB |
Output is correct |
19 |
Correct |
2 ms |
756 KB |
Output is correct |
20 |
Correct |
2 ms |
756 KB |
Output is correct |
21 |
Correct |
3 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
756 KB |
Output is correct |
23 |
Correct |
2 ms |
756 KB |
Output is correct |
24 |
Correct |
2 ms |
756 KB |
Output is correct |
25 |
Correct |
2 ms |
756 KB |
Output is correct |
26 |
Correct |
2 ms |
756 KB |
Output is correct |
27 |
Correct |
2 ms |
756 KB |
Output is correct |
28 |
Correct |
2 ms |
756 KB |
Output is correct |
29 |
Correct |
2 ms |
756 KB |
Output is correct |
30 |
Correct |
2 ms |
756 KB |
Output is correct |
31 |
Correct |
2 ms |
756 KB |
Output is correct |
32 |
Correct |
2 ms |
756 KB |
Output is correct |
33 |
Correct |
2 ms |
756 KB |
Output is correct |
34 |
Correct |
2 ms |
756 KB |
Output is correct |
35 |
Correct |
2 ms |
756 KB |
Output is correct |
36 |
Correct |
2 ms |
756 KB |
Output is correct |
37 |
Correct |
2 ms |
756 KB |
Output is correct |
38 |
Correct |
2 ms |
756 KB |
Output is correct |
39 |
Correct |
2 ms |
756 KB |
Output is correct |
40 |
Correct |
2 ms |
756 KB |
Output is correct |
41 |
Correct |
3 ms |
756 KB |
Output is correct |
42 |
Correct |
2 ms |
756 KB |
Output is correct |
43 |
Correct |
2 ms |
756 KB |
Output is correct |
44 |
Correct |
2 ms |
756 KB |
Output is correct |
45 |
Correct |
2 ms |
756 KB |
Output is correct |
46 |
Correct |
2 ms |
756 KB |
Output is correct |
47 |
Correct |
3 ms |
756 KB |
Output is correct |
48 |
Correct |
3 ms |
756 KB |
Output is correct |
49 |
Correct |
3 ms |
756 KB |
Output is correct |
50 |
Correct |
4 ms |
756 KB |
Output is correct |
51 |
Correct |
5 ms |
756 KB |
Output is correct |
52 |
Correct |
4 ms |
756 KB |
Output is correct |
53 |
Correct |
5 ms |
756 KB |
Output is correct |
54 |
Correct |
5 ms |
756 KB |
Output is correct |
55 |
Correct |
4 ms |
756 KB |
Output is correct |
56 |
Correct |
2 ms |
756 KB |
Output is correct |
57 |
Correct |
2 ms |
756 KB |
Output is correct |
58 |
Correct |
2 ms |
756 KB |
Output is correct |
59 |
Correct |
2 ms |
756 KB |
Output is correct |
60 |
Correct |
2 ms |
756 KB |
Output is correct |
61 |
Correct |
4 ms |
756 KB |
Output is correct |
62 |
Correct |
3 ms |
756 KB |
Output is correct |
63 |
Correct |
3 ms |
756 KB |
Output is correct |
64 |
Correct |
4 ms |
756 KB |
Output is correct |
65 |
Correct |
2 ms |
756 KB |
Output is correct |
66 |
Correct |
2 ms |
756 KB |
Output is correct |
67 |
Correct |
2 ms |
756 KB |
Output is correct |
68 |
Correct |
2 ms |
756 KB |
Output is correct |
69 |
Correct |
2 ms |
756 KB |
Output is correct |
70 |
Correct |
3 ms |
756 KB |
Output is correct |
71 |
Correct |
3 ms |
756 KB |
Output is correct |
72 |
Correct |
3 ms |
756 KB |
Output is correct |
73 |
Correct |
3 ms |
756 KB |
Output is correct |
74 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
756 KB |
Output is correct |
2 |
Correct |
2 ms |
756 KB |
Output is correct |
3 |
Correct |
1 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
2 ms |
756 KB |
Output is correct |
7 |
Correct |
2 ms |
756 KB |
Output is correct |
8 |
Correct |
2 ms |
756 KB |
Output is correct |
9 |
Correct |
2 ms |
756 KB |
Output is correct |
10 |
Correct |
2 ms |
756 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
756 KB |
Output is correct |
13 |
Correct |
2 ms |
756 KB |
Output is correct |
14 |
Correct |
2 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
2 ms |
756 KB |
Output is correct |
17 |
Correct |
2 ms |
756 KB |
Output is correct |
18 |
Correct |
1 ms |
756 KB |
Output is correct |
19 |
Correct |
2 ms |
756 KB |
Output is correct |
20 |
Correct |
2 ms |
756 KB |
Output is correct |
21 |
Correct |
2 ms |
756 KB |
Output is correct |
22 |
Correct |
2 ms |
756 KB |
Output is correct |
23 |
Correct |
2 ms |
756 KB |
Output is correct |
24 |
Correct |
2 ms |
756 KB |
Output is correct |
25 |
Correct |
2 ms |
756 KB |
Output is correct |
26 |
Correct |
2 ms |
756 KB |
Output is correct |
27 |
Correct |
2 ms |
756 KB |
Output is correct |
28 |
Correct |
2 ms |
756 KB |
Output is correct |
29 |
Correct |
2 ms |
756 KB |
Output is correct |
30 |
Correct |
2 ms |
756 KB |
Output is correct |
31 |
Correct |
2 ms |
756 KB |
Output is correct |
32 |
Correct |
2 ms |
756 KB |
Output is correct |
33 |
Correct |
3 ms |
756 KB |
Output is correct |
34 |
Correct |
2 ms |
756 KB |
Output is correct |
35 |
Correct |
3 ms |
756 KB |
Output is correct |
36 |
Correct |
3 ms |
756 KB |
Output is correct |
37 |
Correct |
4 ms |
756 KB |
Output is correct |
38 |
Correct |
4 ms |
756 KB |
Output is correct |
39 |
Correct |
4 ms |
756 KB |
Output is correct |
40 |
Correct |
5 ms |
756 KB |
Output is correct |
41 |
Correct |
5 ms |
756 KB |
Output is correct |
42 |
Correct |
4 ms |
756 KB |
Output is correct |
43 |
Correct |
2 ms |
756 KB |
Output is correct |
44 |
Correct |
3 ms |
756 KB |
Output is correct |
45 |
Correct |
2 ms |
756 KB |
Output is correct |
46 |
Correct |
2 ms |
756 KB |
Output is correct |
47 |
Correct |
2 ms |
756 KB |
Output is correct |
48 |
Correct |
3 ms |
756 KB |
Output is correct |
49 |
Correct |
3 ms |
756 KB |
Output is correct |
50 |
Correct |
3 ms |
756 KB |
Output is correct |
51 |
Correct |
2 ms |
756 KB |
Output is correct |
52 |
Correct |
17 ms |
756 KB |
Output is correct |
53 |
Correct |
23 ms |
756 KB |
Output is correct |
54 |
Correct |
49 ms |
756 KB |
Output is correct |
55 |
Correct |
40 ms |
756 KB |
Output is correct |
56 |
Correct |
100 ms |
756 KB |
Output is correct |
57 |
Correct |
97 ms |
876 KB |
Output is correct |
58 |
Correct |
61 ms |
876 KB |
Output is correct |
59 |
Correct |
62 ms |
876 KB |
Output is correct |
60 |
Correct |
256 ms |
876 KB |
Output is correct |
61 |
Correct |
3 ms |
876 KB |
Output is correct |
62 |
Correct |
21 ms |
876 KB |
Output is correct |
63 |
Correct |
53 ms |
876 KB |
Output is correct |
64 |
Correct |
31 ms |
876 KB |
Output is correct |
65 |
Correct |
53 ms |
876 KB |
Output is correct |
66 |
Correct |
69 ms |
876 KB |
Output is correct |
67 |
Correct |
201 ms |
876 KB |
Output is correct |
68 |
Correct |
121 ms |
876 KB |
Output is correct |
69 |
Correct |
80 ms |
876 KB |
Output is correct |