#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) {
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 <bool> dp(n + 1);
int i, j;
dp[0] = 1;
for(i = 1; i <= n; i++) {
ll s = 0;
for(j = i - 1; j >= 0; j--) {
s += arr[j + 1];
if(dp[j] && check(s, conf, bit)) {
dp[i] = 1;
break;
}
}
}
if(!dp[n]) {
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);
}
//cin.close();
//cout.close();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
508 KB |
Output is correct |
7 |
Correct |
2 ms |
520 KB |
Output is correct |
8 |
Correct |
2 ms |
524 KB |
Output is correct |
9 |
Correct |
2 ms |
528 KB |
Output is correct |
10 |
Correct |
2 ms |
532 KB |
Output is correct |
11 |
Correct |
2 ms |
536 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
2 ms |
684 KB |
Output is correct |
14 |
Correct |
2 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
684 KB |
Output is correct |
16 |
Correct |
2 ms |
684 KB |
Output is correct |
17 |
Correct |
2 ms |
684 KB |
Output is correct |
18 |
Correct |
2 ms |
684 KB |
Output is correct |
19 |
Correct |
2 ms |
684 KB |
Output is correct |
20 |
Correct |
2 ms |
688 KB |
Output is correct |
21 |
Correct |
2 ms |
824 KB |
Output is correct |
22 |
Correct |
2 ms |
824 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
2 ms |
824 KB |
Output is correct |
25 |
Correct |
2 ms |
824 KB |
Output is correct |
26 |
Correct |
2 ms |
824 KB |
Output is correct |
27 |
Correct |
3 ms |
824 KB |
Output is correct |
28 |
Correct |
2 ms |
824 KB |
Output is correct |
29 |
Correct |
2 ms |
824 KB |
Output is correct |
30 |
Correct |
3 ms |
824 KB |
Output is correct |
31 |
Correct |
2 ms |
824 KB |
Output is correct |
32 |
Correct |
2 ms |
824 KB |
Output is correct |
33 |
Correct |
2 ms |
824 KB |
Output is correct |
34 |
Correct |
2 ms |
824 KB |
Output is correct |
35 |
Correct |
2 ms |
824 KB |
Output is correct |
36 |
Correct |
2 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
824 KB |
Output is correct |
2 |
Correct |
2 ms |
824 KB |
Output is correct |
3 |
Correct |
2 ms |
824 KB |
Output is correct |
4 |
Correct |
2 ms |
824 KB |
Output is correct |
5 |
Correct |
2 ms |
824 KB |
Output is correct |
6 |
Correct |
2 ms |
824 KB |
Output is correct |
7 |
Correct |
2 ms |
824 KB |
Output is correct |
8 |
Correct |
2 ms |
824 KB |
Output is correct |
9 |
Correct |
2 ms |
824 KB |
Output is correct |
10 |
Correct |
2 ms |
824 KB |
Output is correct |
11 |
Correct |
2 ms |
824 KB |
Output is correct |
12 |
Correct |
2 ms |
824 KB |
Output is correct |
13 |
Correct |
2 ms |
824 KB |
Output is correct |
14 |
Correct |
2 ms |
824 KB |
Output is correct |
15 |
Correct |
2 ms |
824 KB |
Output is correct |
16 |
Correct |
2 ms |
828 KB |
Output is correct |
17 |
Correct |
2 ms |
832 KB |
Output is correct |
18 |
Correct |
2 ms |
836 KB |
Output is correct |
19 |
Correct |
2 ms |
840 KB |
Output is correct |
20 |
Correct |
2 ms |
840 KB |
Output is correct |
21 |
Correct |
2 ms |
840 KB |
Output is correct |
22 |
Correct |
2 ms |
852 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
988 KB |
Output is correct |
25 |
Correct |
2 ms |
988 KB |
Output is correct |
26 |
Correct |
2 ms |
988 KB |
Output is correct |
27 |
Correct |
2 ms |
988 KB |
Output is correct |
28 |
Correct |
2 ms |
988 KB |
Output is correct |
29 |
Correct |
2 ms |
988 KB |
Output is correct |
30 |
Correct |
2 ms |
988 KB |
Output is correct |
31 |
Correct |
3 ms |
988 KB |
Output is correct |
32 |
Correct |
2 ms |
988 KB |
Output is correct |
33 |
Correct |
2 ms |
988 KB |
Output is correct |
34 |
Correct |
2 ms |
988 KB |
Output is correct |
35 |
Correct |
2 ms |
988 KB |
Output is correct |
36 |
Correct |
2 ms |
988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
988 KB |
Output is correct |
2 |
Correct |
2 ms |
988 KB |
Output is correct |
3 |
Correct |
2 ms |
988 KB |
Output is correct |
4 |
Correct |
2 ms |
988 KB |
Output is correct |
5 |
Correct |
2 ms |
988 KB |
Output is correct |
6 |
Correct |
2 ms |
988 KB |
Output is correct |
7 |
Correct |
2 ms |
988 KB |
Output is correct |
8 |
Correct |
2 ms |
988 KB |
Output is correct |
9 |
Correct |
2 ms |
988 KB |
Output is correct |
10 |
Correct |
2 ms |
988 KB |
Output is correct |
11 |
Correct |
2 ms |
988 KB |
Output is correct |
12 |
Correct |
2 ms |
988 KB |
Output is correct |
13 |
Correct |
2 ms |
1088 KB |
Output is correct |
14 |
Correct |
2 ms |
1088 KB |
Output is correct |
15 |
Correct |
2 ms |
1088 KB |
Output is correct |
16 |
Correct |
2 ms |
1088 KB |
Output is correct |
17 |
Correct |
2 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
2 ms |
1088 KB |
Output is correct |
20 |
Correct |
2 ms |
1088 KB |
Output is correct |
21 |
Correct |
2 ms |
1088 KB |
Output is correct |
22 |
Correct |
2 ms |
1088 KB |
Output is correct |
23 |
Correct |
2 ms |
1088 KB |
Output is correct |
24 |
Correct |
3 ms |
1088 KB |
Output is correct |
25 |
Correct |
2 ms |
1088 KB |
Output is correct |
26 |
Correct |
3 ms |
1088 KB |
Output is correct |
27 |
Correct |
4 ms |
1088 KB |
Output is correct |
28 |
Correct |
7 ms |
1088 KB |
Output is correct |
29 |
Correct |
7 ms |
1088 KB |
Output is correct |
30 |
Correct |
2 ms |
1088 KB |
Output is correct |
31 |
Correct |
4 ms |
1088 KB |
Output is correct |
32 |
Correct |
6 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1088 KB |
Output is correct |
2 |
Correct |
2 ms |
1088 KB |
Output is correct |
3 |
Correct |
2 ms |
1088 KB |
Output is correct |
4 |
Correct |
2 ms |
1088 KB |
Output is correct |
5 |
Correct |
2 ms |
1088 KB |
Output is correct |
6 |
Correct |
2 ms |
1088 KB |
Output is correct |
7 |
Correct |
2 ms |
1088 KB |
Output is correct |
8 |
Correct |
2 ms |
1088 KB |
Output is correct |
9 |
Correct |
2 ms |
1088 KB |
Output is correct |
10 |
Correct |
2 ms |
1196 KB |
Output is correct |
11 |
Correct |
2 ms |
1196 KB |
Output is correct |
12 |
Correct |
2 ms |
1196 KB |
Output is correct |
13 |
Correct |
2 ms |
1200 KB |
Output is correct |
14 |
Correct |
2 ms |
1200 KB |
Output is correct |
15 |
Correct |
2 ms |
1200 KB |
Output is correct |
16 |
Correct |
2 ms |
1200 KB |
Output is correct |
17 |
Correct |
2 ms |
1200 KB |
Output is correct |
18 |
Correct |
2 ms |
1200 KB |
Output is correct |
19 |
Correct |
2 ms |
1200 KB |
Output is correct |
20 |
Correct |
2 ms |
1200 KB |
Output is correct |
21 |
Correct |
2 ms |
1200 KB |
Output is correct |
22 |
Correct |
2 ms |
1200 KB |
Output is correct |
23 |
Correct |
2 ms |
1200 KB |
Output is correct |
24 |
Correct |
2 ms |
1200 KB |
Output is correct |
25 |
Correct |
2 ms |
1200 KB |
Output is correct |
26 |
Correct |
2 ms |
1200 KB |
Output is correct |
27 |
Correct |
2 ms |
1200 KB |
Output is correct |
28 |
Correct |
2 ms |
1260 KB |
Output is correct |
29 |
Correct |
2 ms |
1260 KB |
Output is correct |
30 |
Correct |
2 ms |
1264 KB |
Output is correct |
31 |
Correct |
2 ms |
1272 KB |
Output is correct |
32 |
Correct |
2 ms |
1272 KB |
Output is correct |
33 |
Correct |
2 ms |
1272 KB |
Output is correct |
34 |
Correct |
2 ms |
1272 KB |
Output is correct |
35 |
Correct |
2 ms |
1272 KB |
Output is correct |
36 |
Correct |
2 ms |
1272 KB |
Output is correct |
37 |
Correct |
2 ms |
1272 KB |
Output is correct |
38 |
Correct |
2 ms |
1272 KB |
Output is correct |
39 |
Correct |
2 ms |
1272 KB |
Output is correct |
40 |
Correct |
2 ms |
1272 KB |
Output is correct |
41 |
Correct |
2 ms |
1272 KB |
Output is correct |
42 |
Correct |
2 ms |
1272 KB |
Output is correct |
43 |
Correct |
2 ms |
1272 KB |
Output is correct |
44 |
Correct |
2 ms |
1272 KB |
Output is correct |
45 |
Correct |
2 ms |
1272 KB |
Output is correct |
46 |
Correct |
2 ms |
1272 KB |
Output is correct |
47 |
Correct |
2 ms |
1272 KB |
Output is correct |
48 |
Correct |
2 ms |
1272 KB |
Output is correct |
49 |
Correct |
3 ms |
1272 KB |
Output is correct |
50 |
Correct |
4 ms |
1272 KB |
Output is correct |
51 |
Correct |
7 ms |
1272 KB |
Output is correct |
52 |
Correct |
7 ms |
1272 KB |
Output is correct |
53 |
Correct |
2 ms |
1272 KB |
Output is correct |
54 |
Correct |
4 ms |
1272 KB |
Output is correct |
55 |
Correct |
5 ms |
1272 KB |
Output is correct |
56 |
Correct |
3 ms |
1272 KB |
Output is correct |
57 |
Correct |
6 ms |
1272 KB |
Output is correct |
58 |
Correct |
11 ms |
1272 KB |
Output is correct |
59 |
Correct |
22 ms |
1400 KB |
Output is correct |
60 |
Correct |
24 ms |
1400 KB |
Output is correct |
61 |
Correct |
2 ms |
1400 KB |
Output is correct |
62 |
Correct |
22 ms |
1400 KB |
Output is correct |
63 |
Correct |
22 ms |
1400 KB |
Output is correct |
64 |
Correct |
4 ms |
1400 KB |
Output is correct |
65 |
Correct |
3 ms |
1400 KB |
Output is correct |
66 |
Correct |
3 ms |
1400 KB |
Output is correct |
67 |
Correct |
5 ms |
1400 KB |
Output is correct |
68 |
Correct |
12 ms |
1400 KB |
Output is correct |
69 |
Correct |
23 ms |
1400 KB |
Output is correct |
70 |
Correct |
24 ms |
1400 KB |
Output is correct |
71 |
Correct |
3 ms |
1400 KB |
Output is correct |
72 |
Correct |
21 ms |
1400 KB |
Output is correct |
73 |
Correct |
17 ms |
1400 KB |
Output is correct |
74 |
Correct |
15 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1400 KB |
Output is correct |
2 |
Correct |
2 ms |
1400 KB |
Output is correct |
3 |
Correct |
2 ms |
1400 KB |
Output is correct |
4 |
Correct |
2 ms |
1400 KB |
Output is correct |
5 |
Correct |
2 ms |
1400 KB |
Output is correct |
6 |
Correct |
2 ms |
1400 KB |
Output is correct |
7 |
Correct |
2 ms |
1400 KB |
Output is correct |
8 |
Correct |
2 ms |
1400 KB |
Output is correct |
9 |
Correct |
2 ms |
1400 KB |
Output is correct |
10 |
Correct |
2 ms |
1400 KB |
Output is correct |
11 |
Correct |
2 ms |
1400 KB |
Output is correct |
12 |
Correct |
2 ms |
1400 KB |
Output is correct |
13 |
Correct |
2 ms |
1400 KB |
Output is correct |
14 |
Correct |
2 ms |
1400 KB |
Output is correct |
15 |
Correct |
2 ms |
1400 KB |
Output is correct |
16 |
Correct |
2 ms |
1400 KB |
Output is correct |
17 |
Correct |
2 ms |
1400 KB |
Output is correct |
18 |
Correct |
2 ms |
1400 KB |
Output is correct |
19 |
Correct |
2 ms |
1400 KB |
Output is correct |
20 |
Correct |
2 ms |
1400 KB |
Output is correct |
21 |
Correct |
2 ms |
1400 KB |
Output is correct |
22 |
Correct |
2 ms |
1400 KB |
Output is correct |
23 |
Correct |
2 ms |
1400 KB |
Output is correct |
24 |
Correct |
2 ms |
1404 KB |
Output is correct |
25 |
Correct |
2 ms |
1408 KB |
Output is correct |
26 |
Correct |
2 ms |
1412 KB |
Output is correct |
27 |
Correct |
2 ms |
1416 KB |
Output is correct |
28 |
Correct |
2 ms |
1416 KB |
Output is correct |
29 |
Correct |
2 ms |
1424 KB |
Output is correct |
30 |
Correct |
2 ms |
1428 KB |
Output is correct |
31 |
Correct |
3 ms |
1432 KB |
Output is correct |
32 |
Correct |
3 ms |
1436 KB |
Output is correct |
33 |
Correct |
2 ms |
1440 KB |
Output is correct |
34 |
Correct |
2 ms |
1440 KB |
Output is correct |
35 |
Correct |
2 ms |
1552 KB |
Output is correct |
36 |
Correct |
3 ms |
1580 KB |
Output is correct |
37 |
Correct |
4 ms |
1580 KB |
Output is correct |
38 |
Correct |
6 ms |
1580 KB |
Output is correct |
39 |
Correct |
7 ms |
1580 KB |
Output is correct |
40 |
Correct |
2 ms |
1580 KB |
Output is correct |
41 |
Correct |
4 ms |
1580 KB |
Output is correct |
42 |
Correct |
6 ms |
1580 KB |
Output is correct |
43 |
Correct |
3 ms |
1580 KB |
Output is correct |
44 |
Correct |
7 ms |
1580 KB |
Output is correct |
45 |
Correct |
12 ms |
1580 KB |
Output is correct |
46 |
Correct |
23 ms |
1580 KB |
Output is correct |
47 |
Correct |
25 ms |
1620 KB |
Output is correct |
48 |
Correct |
2 ms |
1620 KB |
Output is correct |
49 |
Correct |
23 ms |
1620 KB |
Output is correct |
50 |
Correct |
22 ms |
1620 KB |
Output is correct |
51 |
Incorrect |
2 ms |
1620 KB |
Output isn't correct |
52 |
Halted |
0 ms |
0 KB |
- |