#include <bits/stdc++.h>
#pragma GCC optimize("O3")
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
#define double long double
using namespace std;
ll n,a,b;
ll nums[2005];
vector<ll> dp1[2005];
ll dp2[2005][2005];
ll poww(ll n){
ll sus = 1;
FOR(i,0,n){
sus *= 2;
}
return sus;
}
int check(ll v){
FOR(i,0,n+2) FOR(j,0,n+2) dp2[i][j] = 1000000000000000;
FOR(i,0,n+1) dp1[i] = {1000000000000000,1000000000000000};
dp1[0] = {0,0};
if (a==1){
FOR(i,0,n+1){
ll cur = 0;
FOR(x, i+1, n+1){
cur += nums[x];
if ((cur&v)==cur){
dp1[x] = {cur, min(dp1[x][1], dp1[i][1] + 1)};
}
}
}
if ((dp1[n][0]&v)==dp1[n][0] && dp1[n][1] <= b) return 1;
return 0;
}else{
dp2[0][0] = 0;
FOR(i,0,n+1){
FOR(j,0,n+1){
ll cur = 0;
FOR(x, i+1, n+1){
cur += nums[x];
if ((cur&v)==cur) dp2[x][j+1] = min(dp2[x][j+1], dp2[i][j] | cur);
}
}
}
FOR(i,a,b+1){
if ((dp2[n][i]&v) == dp2[n][i]) return 1;
}
}
return 0;
}
int main(){
cin >> n >> a >> b;
FOR(i,0,n) cin >> nums[i+1];
ll sus = poww(50)-1;
FORNEG(i, 49, -1){
sus -= poww(i);
if (check(sus)) continue;
else sus += poww(i);
}
cout << sus;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
416 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
356 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
360 KB |
Output is correct |
28 |
Correct |
1 ms |
356 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
444 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
360 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
356 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
356 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
360 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
484 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
360 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
484 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
480 KB |
Output is correct |
25 |
Correct |
2 ms |
612 KB |
Output is correct |
26 |
Correct |
2 ms |
732 KB |
Output is correct |
27 |
Correct |
3 ms |
724 KB |
Output is correct |
28 |
Correct |
3 ms |
852 KB |
Output is correct |
29 |
Correct |
3 ms |
852 KB |
Output is correct |
30 |
Correct |
3 ms |
740 KB |
Output is correct |
31 |
Correct |
3 ms |
852 KB |
Output is correct |
32 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
360 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
356 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
356 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
2 ms |
596 KB |
Output is correct |
48 |
Correct |
2 ms |
596 KB |
Output is correct |
49 |
Correct |
2 ms |
612 KB |
Output is correct |
50 |
Correct |
3 ms |
724 KB |
Output is correct |
51 |
Correct |
3 ms |
852 KB |
Output is correct |
52 |
Correct |
3 ms |
852 KB |
Output is correct |
53 |
Correct |
3 ms |
852 KB |
Output is correct |
54 |
Correct |
3 ms |
852 KB |
Output is correct |
55 |
Correct |
3 ms |
860 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
2 ms |
724 KB |
Output is correct |
59 |
Correct |
2 ms |
740 KB |
Output is correct |
60 |
Correct |
2 ms |
852 KB |
Output is correct |
61 |
Correct |
3 ms |
852 KB |
Output is correct |
62 |
Correct |
2 ms |
852 KB |
Output is correct |
63 |
Correct |
3 ms |
740 KB |
Output is correct |
64 |
Correct |
26 ms |
780 KB |
Output is correct |
65 |
Correct |
5 ms |
596 KB |
Output is correct |
66 |
Correct |
9 ms |
596 KB |
Output is correct |
67 |
Correct |
14 ms |
616 KB |
Output is correct |
68 |
Correct |
22 ms |
744 KB |
Output is correct |
69 |
Correct |
29 ms |
852 KB |
Output is correct |
70 |
Correct |
28 ms |
832 KB |
Output is correct |
71 |
Correct |
30 ms |
852 KB |
Output is correct |
72 |
Correct |
33 ms |
852 KB |
Output is correct |
73 |
Correct |
33 ms |
744 KB |
Output is correct |
74 |
Correct |
31 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
488 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
488 KB |
Output is correct |
30 |
Correct |
1 ms |
484 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
2 ms |
596 KB |
Output is correct |
35 |
Correct |
2 ms |
620 KB |
Output is correct |
36 |
Correct |
2 ms |
616 KB |
Output is correct |
37 |
Correct |
3 ms |
724 KB |
Output is correct |
38 |
Correct |
3 ms |
852 KB |
Output is correct |
39 |
Correct |
3 ms |
852 KB |
Output is correct |
40 |
Correct |
3 ms |
852 KB |
Output is correct |
41 |
Correct |
3 ms |
852 KB |
Output is correct |
42 |
Correct |
3 ms |
744 KB |
Output is correct |
43 |
Correct |
1 ms |
596 KB |
Output is correct |
44 |
Correct |
2 ms |
664 KB |
Output is correct |
45 |
Correct |
2 ms |
740 KB |
Output is correct |
46 |
Correct |
2 ms |
852 KB |
Output is correct |
47 |
Correct |
2 ms |
852 KB |
Output is correct |
48 |
Correct |
2 ms |
852 KB |
Output is correct |
49 |
Correct |
2 ms |
744 KB |
Output is correct |
50 |
Correct |
2 ms |
852 KB |
Output is correct |
51 |
Correct |
2 ms |
852 KB |
Output is correct |
52 |
Correct |
41 ms |
5204 KB |
Output is correct |
53 |
Correct |
74 ms |
7796 KB |
Output is correct |
54 |
Correct |
126 ms |
12244 KB |
Output is correct |
55 |
Correct |
124 ms |
12264 KB |
Output is correct |
56 |
Correct |
513 ms |
31856 KB |
Output is correct |
57 |
Correct |
467 ms |
31828 KB |
Output is correct |
58 |
Correct |
488 ms |
31852 KB |
Output is correct |
59 |
Correct |
459 ms |
31856 KB |
Output is correct |
60 |
Correct |
501 ms |
31856 KB |
Output is correct |
61 |
Correct |
2 ms |
852 KB |
Output is correct |
62 |
Correct |
62 ms |
7772 KB |
Output is correct |
63 |
Correct |
146 ms |
12256 KB |
Output is correct |
64 |
Correct |
132 ms |
12244 KB |
Output is correct |
65 |
Correct |
258 ms |
21460 KB |
Output is correct |
66 |
Correct |
388 ms |
27768 KB |
Output is correct |
67 |
Correct |
473 ms |
31852 KB |
Output is correct |
68 |
Correct |
495 ms |
31868 KB |
Output is correct |
69 |
Correct |
479 ms |
31852 KB |
Output is correct |