#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 100 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;
ll n, a, b, Y[N], pref[N], max_value, ans = INF, mxY = 0, dp[N][N], dp2[2005];
bool match(ll bit, ll prefix, ll cur){
for(ll i = 50; i >= bit; i--){
ll f1 = ((1ll << i) & prefix);
ll f2 = ((1ll << i) & cur);
if(f2 == 0)
continue;
if(f1 != f2)
return false;
}
return true;
}
int main(){
speed;
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
cin >> Y[i];
pref[i] = pref[i - 1] + Y[i];
}
ll current_bit_prefix = 0;
if(a == 1){
for(ll bit = 50; bit >= 0; bit--){
for(int i = 0; i <= n; i++){
dp2[i] = INF;
}dp2[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < i; j++){
ll sum = pref[i] - pref[j];
if((1ll << bit) & sum)
continue;
if(!match(bit + 1, current_bit_prefix, sum))
continue;
dp2[i] = min(dp2[i], dp2[j] + 1);
}
}
if(dp2[n] <= b){
continue;
}else{
current_bit_prefix ^= (1ll << bit);
}
}
cout << current_bit_prefix << endl;
return 0;
}
for(ll bit = 50; bit >= 0; bit--){
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j] = 0;
}
}
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int part = 0; part < n; part++){
for(int j = 0; j < i; j++){
ll sum = pref[i] - pref[j];
if(dp[j][part] == 0)
continue;
if(!match(bit + 1, current_bit_prefix, sum))
continue;
if((sum & (1ll << bit)))
continue;
dp[i][part + 1] = 1;
}
// if(bit == 0)
// cout << i << " " << part + 1 << " " << dp[i][part + 1] << endl;
}
}
// return 0;
int fl = 0;
for(int part = a; part <= b; part++){
if(dp[n][part]){
fl = 1;
break;
}
}
// cout << "F " << bit << " " << fl << endl;
if(fl)
continue;
current_bit_prefix ^= (1ll << bit);
}
cout << current_bit_prefix << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
272 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
224 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
212 KB |
Output is correct |
26 |
Correct |
3 ms |
212 KB |
Output is correct |
27 |
Correct |
4 ms |
212 KB |
Output is correct |
28 |
Correct |
5 ms |
320 KB |
Output is correct |
29 |
Correct |
5 ms |
320 KB |
Output is correct |
30 |
Correct |
7 ms |
320 KB |
Output is correct |
31 |
Correct |
5 ms |
212 KB |
Output is correct |
32 |
Correct |
7 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
224 KB |
Output is correct |
16 |
Correct |
0 ms |
224 KB |
Output is correct |
17 |
Correct |
0 ms |
224 KB |
Output is correct |
18 |
Correct |
1 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
2 ms |
352 KB |
Output is correct |
22 |
Correct |
2 ms |
352 KB |
Output is correct |
23 |
Correct |
2 ms |
352 KB |
Output is correct |
24 |
Correct |
2 ms |
352 KB |
Output is correct |
25 |
Correct |
2 ms |
352 KB |
Output is correct |
26 |
Correct |
2 ms |
352 KB |
Output is correct |
27 |
Correct |
0 ms |
224 KB |
Output is correct |
28 |
Correct |
0 ms |
224 KB |
Output is correct |
29 |
Correct |
1 ms |
224 KB |
Output is correct |
30 |
Correct |
1 ms |
224 KB |
Output is correct |
31 |
Correct |
0 ms |
224 KB |
Output is correct |
32 |
Correct |
1 ms |
224 KB |
Output is correct |
33 |
Correct |
1 ms |
224 KB |
Output is correct |
34 |
Correct |
1 ms |
224 KB |
Output is correct |
35 |
Correct |
1 ms |
224 KB |
Output is correct |
36 |
Correct |
1 ms |
224 KB |
Output is correct |
37 |
Correct |
1 ms |
224 KB |
Output is correct |
38 |
Correct |
1 ms |
224 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
212 KB |
Output is correct |
42 |
Correct |
2 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
2 ms |
212 KB |
Output is correct |
46 |
Correct |
2 ms |
212 KB |
Output is correct |
47 |
Correct |
2 ms |
212 KB |
Output is correct |
48 |
Correct |
2 ms |
212 KB |
Output is correct |
49 |
Correct |
3 ms |
212 KB |
Output is correct |
50 |
Correct |
4 ms |
212 KB |
Output is correct |
51 |
Correct |
5 ms |
212 KB |
Output is correct |
52 |
Correct |
5 ms |
212 KB |
Output is correct |
53 |
Correct |
6 ms |
212 KB |
Output is correct |
54 |
Correct |
5 ms |
212 KB |
Output is correct |
55 |
Correct |
5 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
3 ms |
212 KB |
Output is correct |
58 |
Correct |
3 ms |
212 KB |
Output is correct |
59 |
Correct |
4 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
328 KB |
Output is correct |
61 |
Correct |
3 ms |
212 KB |
Output is correct |
62 |
Correct |
4 ms |
212 KB |
Output is correct |
63 |
Correct |
4 ms |
324 KB |
Output is correct |
64 |
Correct |
143 ms |
384 KB |
Output is correct |
65 |
Correct |
7 ms |
368 KB |
Output is correct |
66 |
Correct |
16 ms |
340 KB |
Output is correct |
67 |
Correct |
22 ms |
392 KB |
Output is correct |
68 |
Correct |
35 ms |
340 KB |
Output is correct |
69 |
Correct |
42 ms |
340 KB |
Output is correct |
70 |
Correct |
41 ms |
388 KB |
Output is correct |
71 |
Correct |
46 ms |
384 KB |
Output is correct |
72 |
Correct |
52 ms |
340 KB |
Output is correct |
73 |
Correct |
54 ms |
400 KB |
Output is correct |
74 |
Correct |
55 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
216 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
2 ms |
320 KB |
Output is correct |
27 |
Correct |
2 ms |
212 KB |
Output is correct |
28 |
Correct |
2 ms |
324 KB |
Output is correct |
29 |
Correct |
2 ms |
324 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
232 KB |
Output is correct |
34 |
Correct |
2 ms |
328 KB |
Output is correct |
35 |
Correct |
3 ms |
324 KB |
Output is correct |
36 |
Correct |
3 ms |
212 KB |
Output is correct |
37 |
Correct |
4 ms |
212 KB |
Output is correct |
38 |
Correct |
5 ms |
320 KB |
Output is correct |
39 |
Correct |
5 ms |
212 KB |
Output is correct |
40 |
Correct |
6 ms |
212 KB |
Output is correct |
41 |
Correct |
5 ms |
328 KB |
Output is correct |
42 |
Correct |
5 ms |
332 KB |
Output is correct |
43 |
Correct |
2 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
212 KB |
Output is correct |
45 |
Correct |
3 ms |
212 KB |
Output is correct |
46 |
Correct |
3 ms |
324 KB |
Output is correct |
47 |
Correct |
3 ms |
212 KB |
Output is correct |
48 |
Correct |
5 ms |
212 KB |
Output is correct |
49 |
Correct |
4 ms |
212 KB |
Output is correct |
50 |
Correct |
3 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
212 KB |
Output is correct |
52 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |