#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
using namespace std;
inline bool check(ll s, ll conf, int bit) {
return ((s | conf) >> bit) == (conf >> bit);
}
inline ll solve1(int n, int a, int b, vector <int> &arr) {
ll sum = 0;
for(auto it : arr) {
sum += it;
}
ll conf = 0;
for(int bit = 60; bit >= 0; bit--) {
if((1LL << bit) > sum) {
continue;
}
vector < vector <bool> > dp;
int i, j;
dp.resize(n + 1);
for(i = 0; i <= n; i++) {
dp[i].resize(b + 1);
}
dp[0][0] = 1;
for(i = 1; i <= n; i++) {
for(int k = 1; k <= b; k++) {
ll s = 0;
for(j = i - 1; j >= 0; j--) {
s += arr[j + 1];
if(dp[j][k - 1] && check(s, conf, bit)) {
dp[i][k] = 1;
break;
}
}
}
}
bool ok = 0;
for(i = a; i <= b; i++) {
if(dp[n][i]) {
ok = 1;
}
}
if(!ok) {
conf += (1LL << bit);
}
}
return conf;
}
inline ll solve2(int n, vector <int> &arr, int b) {
ll sum = 0;
for(auto it : arr) {
sum += it;
}
ll conf = 0;
for(int bit = 60; bit >= 0; bit--) {
if((1LL << bit) > sum) {
continue;
}
vector < pair <bool, int> > dp(n + 1);
int i, j;
dp[0] = {1, 0};
for(i = 1; i <= n; i++) {
ll s = 0;
dp[i].second = n + 1;
for(j = i - 1; j >= 0; j--) {
s += arr[j + 1];
if(dp[j].first && check(s, conf, bit)) {
dp[i].first = 1;
dp[i].second = min(dp[i].second, dp[j].second + 1);
}
}
}
if(!dp[n].first || dp[n].second > b) {
conf += (1LL << bit);
}
}
return conf;
}
int main() {
//ifstream cin("C.in");
//ofstream cout("C.out");
int i, n, a, b;
ios::sync_with_stdio(false);
cin >> n >> a >> b;
vector <int> arr(n + 1);
for(i = 1; i <= n; i++) {
cin >> arr[i];
}
if(n <= 100) {
cout << solve1(n, a, b, arr);
}
else {
cout << solve2(n, arr, b);
}
//cin.close();
//cout.close();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
3 ms |
464 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
632 KB |
Output is correct |
14 |
Correct |
2 ms |
748 KB |
Output is correct |
15 |
Correct |
2 ms |
748 KB |
Output is correct |
16 |
Correct |
2 ms |
748 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
4 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
748 KB |
Output is correct |
22 |
Correct |
2 ms |
748 KB |
Output is correct |
23 |
Correct |
2 ms |
748 KB |
Output is correct |
24 |
Correct |
2 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
2 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
748 KB |
Output is correct |
28 |
Correct |
2 ms |
748 KB |
Output is correct |
29 |
Correct |
2 ms |
748 KB |
Output is correct |
30 |
Correct |
2 ms |
748 KB |
Output is correct |
31 |
Correct |
2 ms |
748 KB |
Output is correct |
32 |
Correct |
2 ms |
748 KB |
Output is correct |
33 |
Correct |
2 ms |
748 KB |
Output is correct |
34 |
Correct |
2 ms |
748 KB |
Output is correct |
35 |
Correct |
2 ms |
748 KB |
Output is correct |
36 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
760 KB |
Output is correct |
11 |
Correct |
3 ms |
760 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
3 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
2 ms |
760 KB |
Output is correct |
20 |
Correct |
3 ms |
760 KB |
Output is correct |
21 |
Correct |
2 ms |
760 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
3 ms |
760 KB |
Output is correct |
24 |
Correct |
3 ms |
760 KB |
Output is correct |
25 |
Correct |
2 ms |
760 KB |
Output is correct |
26 |
Correct |
2 ms |
760 KB |
Output is correct |
27 |
Correct |
2 ms |
760 KB |
Output is correct |
28 |
Correct |
2 ms |
760 KB |
Output is correct |
29 |
Correct |
2 ms |
760 KB |
Output is correct |
30 |
Correct |
3 ms |
760 KB |
Output is correct |
31 |
Correct |
2 ms |
760 KB |
Output is correct |
32 |
Correct |
2 ms |
760 KB |
Output is correct |
33 |
Correct |
2 ms |
760 KB |
Output is correct |
34 |
Correct |
3 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
760 KB |
Output is correct |
36 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
760 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
16 |
Correct |
3 ms |
760 KB |
Output is correct |
17 |
Correct |
3 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
2 ms |
760 KB |
Output is correct |
20 |
Correct |
2 ms |
760 KB |
Output is correct |
21 |
Correct |
2 ms |
760 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
760 KB |
Output is correct |
24 |
Correct |
3 ms |
760 KB |
Output is correct |
25 |
Correct |
3 ms |
760 KB |
Output is correct |
26 |
Correct |
3 ms |
760 KB |
Output is correct |
27 |
Correct |
4 ms |
760 KB |
Output is correct |
28 |
Correct |
7 ms |
760 KB |
Output is correct |
29 |
Correct |
7 ms |
760 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
31 |
Correct |
5 ms |
760 KB |
Output is correct |
32 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
760 KB |
Output is correct |
7 |
Correct |
2 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
760 KB |
Output is correct |
11 |
Correct |
2 ms |
760 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
760 KB |
Output is correct |
14 |
Correct |
2 ms |
760 KB |
Output is correct |
15 |
Correct |
2 ms |
760 KB |
Output is correct |
16 |
Correct |
2 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
760 KB |
Output is correct |
18 |
Correct |
2 ms |
760 KB |
Output is correct |
19 |
Correct |
3 ms |
760 KB |
Output is correct |
20 |
Correct |
2 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
760 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
760 KB |
Output is correct |
24 |
Correct |
2 ms |
760 KB |
Output is correct |
25 |
Correct |
2 ms |
760 KB |
Output is correct |
26 |
Correct |
2 ms |
760 KB |
Output is correct |
27 |
Correct |
2 ms |
760 KB |
Output is correct |
28 |
Correct |
2 ms |
760 KB |
Output is correct |
29 |
Correct |
2 ms |
760 KB |
Output is correct |
30 |
Correct |
2 ms |
760 KB |
Output is correct |
31 |
Correct |
2 ms |
760 KB |
Output is correct |
32 |
Correct |
2 ms |
760 KB |
Output is correct |
33 |
Correct |
2 ms |
760 KB |
Output is correct |
34 |
Correct |
3 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
760 KB |
Output is correct |
36 |
Correct |
2 ms |
760 KB |
Output is correct |
37 |
Correct |
2 ms |
760 KB |
Output is correct |
38 |
Correct |
2 ms |
760 KB |
Output is correct |
39 |
Correct |
2 ms |
760 KB |
Output is correct |
40 |
Correct |
2 ms |
760 KB |
Output is correct |
41 |
Correct |
2 ms |
760 KB |
Output is correct |
42 |
Correct |
2 ms |
760 KB |
Output is correct |
43 |
Correct |
2 ms |
760 KB |
Output is correct |
44 |
Correct |
2 ms |
760 KB |
Output is correct |
45 |
Correct |
2 ms |
760 KB |
Output is correct |
46 |
Correct |
2 ms |
760 KB |
Output is correct |
47 |
Correct |
2 ms |
760 KB |
Output is correct |
48 |
Correct |
2 ms |
760 KB |
Output is correct |
49 |
Correct |
3 ms |
760 KB |
Output is correct |
50 |
Correct |
4 ms |
760 KB |
Output is correct |
51 |
Correct |
7 ms |
760 KB |
Output is correct |
52 |
Correct |
7 ms |
760 KB |
Output is correct |
53 |
Correct |
2 ms |
760 KB |
Output is correct |
54 |
Correct |
4 ms |
760 KB |
Output is correct |
55 |
Correct |
6 ms |
760 KB |
Output is correct |
56 |
Correct |
3 ms |
760 KB |
Output is correct |
57 |
Correct |
6 ms |
760 KB |
Output is correct |
58 |
Correct |
12 ms |
760 KB |
Output is correct |
59 |
Correct |
42 ms |
760 KB |
Output is correct |
60 |
Correct |
38 ms |
760 KB |
Output is correct |
61 |
Correct |
2 ms |
760 KB |
Output is correct |
62 |
Correct |
27 ms |
760 KB |
Output is correct |
63 |
Correct |
23 ms |
760 KB |
Output is correct |
64 |
Correct |
4 ms |
760 KB |
Output is correct |
65 |
Correct |
4 ms |
760 KB |
Output is correct |
66 |
Correct |
5 ms |
760 KB |
Output is correct |
67 |
Correct |
6 ms |
760 KB |
Output is correct |
68 |
Correct |
12 ms |
760 KB |
Output is correct |
69 |
Correct |
23 ms |
760 KB |
Output is correct |
70 |
Correct |
24 ms |
760 KB |
Output is correct |
71 |
Correct |
4 ms |
760 KB |
Output is correct |
72 |
Correct |
23 ms |
764 KB |
Output is correct |
73 |
Correct |
16 ms |
764 KB |
Output is correct |
74 |
Correct |
16 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Correct |
2 ms |
764 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
2 ms |
764 KB |
Output is correct |
5 |
Correct |
2 ms |
764 KB |
Output is correct |
6 |
Correct |
2 ms |
764 KB |
Output is correct |
7 |
Correct |
2 ms |
764 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
764 KB |
Output is correct |
10 |
Correct |
2 ms |
764 KB |
Output is correct |
11 |
Correct |
2 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
2 ms |
764 KB |
Output is correct |
15 |
Correct |
2 ms |
764 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
2 ms |
764 KB |
Output is correct |
18 |
Correct |
2 ms |
764 KB |
Output is correct |
19 |
Correct |
2 ms |
764 KB |
Output is correct |
20 |
Correct |
2 ms |
764 KB |
Output is correct |
21 |
Correct |
2 ms |
764 KB |
Output is correct |
22 |
Correct |
2 ms |
764 KB |
Output is correct |
23 |
Correct |
2 ms |
764 KB |
Output is correct |
24 |
Correct |
2 ms |
764 KB |
Output is correct |
25 |
Correct |
2 ms |
764 KB |
Output is correct |
26 |
Correct |
2 ms |
764 KB |
Output is correct |
27 |
Correct |
2 ms |
764 KB |
Output is correct |
28 |
Correct |
2 ms |
764 KB |
Output is correct |
29 |
Correct |
2 ms |
764 KB |
Output is correct |
30 |
Correct |
2 ms |
764 KB |
Output is correct |
31 |
Correct |
2 ms |
764 KB |
Output is correct |
32 |
Correct |
2 ms |
764 KB |
Output is correct |
33 |
Correct |
2 ms |
764 KB |
Output is correct |
34 |
Correct |
2 ms |
764 KB |
Output is correct |
35 |
Correct |
2 ms |
764 KB |
Output is correct |
36 |
Correct |
3 ms |
764 KB |
Output is correct |
37 |
Correct |
4 ms |
764 KB |
Output is correct |
38 |
Correct |
7 ms |
764 KB |
Output is correct |
39 |
Correct |
7 ms |
764 KB |
Output is correct |
40 |
Correct |
2 ms |
764 KB |
Output is correct |
41 |
Correct |
4 ms |
764 KB |
Output is correct |
42 |
Correct |
6 ms |
764 KB |
Output is correct |
43 |
Correct |
3 ms |
764 KB |
Output is correct |
44 |
Correct |
6 ms |
764 KB |
Output is correct |
45 |
Correct |
12 ms |
764 KB |
Output is correct |
46 |
Correct |
28 ms |
764 KB |
Output is correct |
47 |
Correct |
27 ms |
764 KB |
Output is correct |
48 |
Correct |
2 ms |
764 KB |
Output is correct |
49 |
Correct |
22 ms |
764 KB |
Output is correct |
50 |
Correct |
23 ms |
764 KB |
Output is correct |
51 |
Correct |
2 ms |
764 KB |
Output is correct |
52 |
Correct |
16 ms |
764 KB |
Output is correct |
53 |
Correct |
16 ms |
764 KB |
Output is correct |
54 |
Correct |
43 ms |
764 KB |
Output is correct |
55 |
Correct |
49 ms |
764 KB |
Output is correct |
56 |
Correct |
100 ms |
764 KB |
Output is correct |
57 |
Correct |
93 ms |
764 KB |
Output is correct |
58 |
Correct |
110 ms |
868 KB |
Output is correct |
59 |
Correct |
119 ms |
868 KB |
Output is correct |
60 |
Correct |
118 ms |
872 KB |
Output is correct |
61 |
Correct |
2 ms |
872 KB |
Output is correct |
62 |
Correct |
15 ms |
872 KB |
Output is correct |
63 |
Correct |
44 ms |
872 KB |
Output is correct |
64 |
Correct |
26 ms |
884 KB |
Output is correct |
65 |
Correct |
49 ms |
1020 KB |
Output is correct |
66 |
Correct |
77 ms |
1020 KB |
Output is correct |
67 |
Correct |
119 ms |
1020 KB |
Output is correct |
68 |
Correct |
176 ms |
1036 KB |
Output is correct |
69 |
Correct |
101 ms |
1036 KB |
Output is correct |