#include <bits/stdc++.h>
using namespace std;
int n, a, b;
long long arr[2005];
long long prefix[2005];
vector<vector<int>> v;
long long res = 0;
inline long long sum(int i, int j){
if(i > j) swap(i, j);
return prefix[j]-prefix[i-1];
}
bool check(vector<vector<int>> &tmp){
if(n>100){
int dp[n+1]; fill(dp, dp+n+1, n+1);
dp[0] = 0;
for(int i = 1; i<=n; i++){
for(auto j : tmp[i]) dp[i] = min(dp[j-1]+1, dp[i]);
}
if(dp[n] == -1 || dp[n] > b) return false;
return 1;
}
bitset<105> dp[n+1];
dp[0].reset();
dp[0].set(0);
for(int i = 1; i<=n; i++){
dp[i].reset();
for(int j : tmp[i]) dp[i] |= (dp[j-1]<<1);
}
for(int i = a; i<=b; i++){
if(dp[n].test(i)) return 1;
}
return 0;
}
int main(){
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
for(int i = 1; i<=n; i++) cin >> arr[i];
prefix[0] = 0;
for(int i = 1; i<=n; i++) prefix[i] = prefix[i-1]+arr[i];
v.resize(n+1);
for(int i = 1; i<=n; i++){
for(int j = i; j<=n; j++){
v[j].push_back(i);
}
}
for(int m = 60; m>=0; m--){
vector<vector<int>> tmp;
tmp.resize(n+1);
for(int i = 1; i<=n; i++){
for(auto &x : v[i]){
if(sum(x, i)&(1ll<<m)) continue;
else tmp[i].push_back(x);
}
}
if(check(tmp)){
v = tmp;
}
else res += 1ll<<m;
}
cout << res << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
376 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
400 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
236 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
2 ms |
364 KB |
Output is correct |
35 |
Correct |
2 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
63 ms |
424 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
3 ms |
364 KB |
Output is correct |
27 |
Correct |
4 ms |
364 KB |
Output is correct |
28 |
Correct |
4 ms |
364 KB |
Output is correct |
29 |
Correct |
4 ms |
364 KB |
Output is correct |
30 |
Correct |
4 ms |
364 KB |
Output is correct |
31 |
Correct |
4 ms |
364 KB |
Output is correct |
32 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
62 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
2 ms |
364 KB |
Output is correct |
41 |
Correct |
2 ms |
364 KB |
Output is correct |
42 |
Correct |
2 ms |
364 KB |
Output is correct |
43 |
Correct |
2 ms |
364 KB |
Output is correct |
44 |
Correct |
2 ms |
364 KB |
Output is correct |
45 |
Correct |
2 ms |
364 KB |
Output is correct |
46 |
Correct |
2 ms |
364 KB |
Output is correct |
47 |
Correct |
2 ms |
364 KB |
Output is correct |
48 |
Correct |
2 ms |
364 KB |
Output is correct |
49 |
Correct |
3 ms |
364 KB |
Output is correct |
50 |
Correct |
4 ms |
364 KB |
Output is correct |
51 |
Correct |
5 ms |
364 KB |
Output is correct |
52 |
Correct |
4 ms |
364 KB |
Output is correct |
53 |
Correct |
5 ms |
364 KB |
Output is correct |
54 |
Correct |
4 ms |
364 KB |
Output is correct |
55 |
Correct |
4 ms |
364 KB |
Output is correct |
56 |
Correct |
1 ms |
364 KB |
Output is correct |
57 |
Correct |
2 ms |
364 KB |
Output is correct |
58 |
Correct |
2 ms |
364 KB |
Output is correct |
59 |
Correct |
3 ms |
364 KB |
Output is correct |
60 |
Correct |
3 ms |
364 KB |
Output is correct |
61 |
Correct |
3 ms |
364 KB |
Output is correct |
62 |
Correct |
3 ms |
364 KB |
Output is correct |
63 |
Correct |
3 ms |
364 KB |
Output is correct |
64 |
Correct |
4 ms |
364 KB |
Output is correct |
65 |
Correct |
2 ms |
364 KB |
Output is correct |
66 |
Correct |
2 ms |
364 KB |
Output is correct |
67 |
Correct |
2 ms |
364 KB |
Output is correct |
68 |
Correct |
3 ms |
364 KB |
Output is correct |
69 |
Correct |
3 ms |
364 KB |
Output is correct |
70 |
Correct |
3 ms |
364 KB |
Output is correct |
71 |
Correct |
3 ms |
364 KB |
Output is correct |
72 |
Correct |
3 ms |
364 KB |
Output is correct |
73 |
Correct |
3 ms |
364 KB |
Output is correct |
74 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
2 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
3 ms |
364 KB |
Output is correct |
37 |
Correct |
4 ms |
364 KB |
Output is correct |
38 |
Correct |
4 ms |
364 KB |
Output is correct |
39 |
Correct |
4 ms |
364 KB |
Output is correct |
40 |
Correct |
5 ms |
364 KB |
Output is correct |
41 |
Correct |
4 ms |
364 KB |
Output is correct |
42 |
Correct |
4 ms |
364 KB |
Output is correct |
43 |
Correct |
2 ms |
364 KB |
Output is correct |
44 |
Correct |
2 ms |
364 KB |
Output is correct |
45 |
Correct |
3 ms |
364 KB |
Output is correct |
46 |
Correct |
3 ms |
364 KB |
Output is correct |
47 |
Correct |
3 ms |
364 KB |
Output is correct |
48 |
Correct |
3 ms |
364 KB |
Output is correct |
49 |
Correct |
4 ms |
636 KB |
Output is correct |
50 |
Correct |
3 ms |
364 KB |
Output is correct |
51 |
Correct |
3 ms |
364 KB |
Output is correct |
52 |
Correct |
45 ms |
2344 KB |
Output is correct |
53 |
Correct |
75 ms |
3908 KB |
Output is correct |
54 |
Correct |
144 ms |
5796 KB |
Output is correct |
55 |
Correct |
135 ms |
5936 KB |
Output is correct |
56 |
Correct |
525 ms |
21916 KB |
Output is correct |
57 |
Correct |
522 ms |
21912 KB |
Output is correct |
58 |
Correct |
494 ms |
21760 KB |
Output is correct |
59 |
Correct |
493 ms |
21760 KB |
Output is correct |
60 |
Correct |
528 ms |
21760 KB |
Output is correct |
61 |
Correct |
3 ms |
364 KB |
Output is correct |
62 |
Correct |
77 ms |
3776 KB |
Output is correct |
63 |
Correct |
143 ms |
5792 KB |
Output is correct |
64 |
Correct |
131 ms |
5820 KB |
Output is correct |
65 |
Correct |
264 ms |
12172 KB |
Output is correct |
66 |
Correct |
393 ms |
17808 KB |
Output is correct |
67 |
Correct |
503 ms |
21760 KB |
Output is correct |
68 |
Correct |
533 ms |
22000 KB |
Output is correct |
69 |
Correct |
512 ms |
21900 KB |
Output is correct |