#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int in() {
int result = 0;
char ch = getchar_unlocked();
while (true) {
if(ch >= '0' && ch <= '9')
break;
ch = getchar_unlocked();
}
result = ch-'0';
while(true) {
ch = getchar_unlocked();
if (ch < '0' || ch > '9')
break;
result = result*10 + (ch - '0');
}
return result;
}
inline void out(ll x) {
ll rev=x;
int count = 0;
if(x == 0) {
putchar_unlocked('0');
putchar_unlocked('\n');
return;
}
while((rev % 10) == 0) {
++count;
rev /= 10;
} //obtain the count of the number of 0s
rev = 0;
while(x != 0) {
rev = rev*10 + x % 10;
x /= 10;
} //store reverse of N in rev
while(rev != 0) {
putchar_unlocked(rev % 10 + '0');
rev /= 10;
}
while(count--)
putchar_unlocked('0');
putchar_unlocked('\n');
}
const int mxN=2000;
int n, a, b, dp[mxN+1][mxN+1];
ll y[mxN];
inline bool can(ll x) {
if(a>1)
memset(dp[0], 0, 4*(b+1));
dp[0][0]=a>1;
for(int i=1; i<=n; ++i) {
if(a==1) {
dp[0][i]=b+1;
ll ys=0;
for(int j=i-1; j>=0; --j) {
ys+=y[j];
if(!(ys&~x))
dp[0][i]=min(dp[0][j]+1, dp[0][i]);
}
} else {
memset(dp[i], 0, 4*(b+1));
ll ys=0;
for(int j=i-1; j>=0; --j) {
ys+=y[j];
if(!(ys&~x))
for(int k=1; k<=b; ++k)
dp[i][k]|=dp[j][k-1];
}
}
}
if(a==1)
return dp[0][n]<=b;
for(int i=a; i<=b; ++i)
if(dp[n][i])
return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
n=in(), a=in(), b=in();
for(int i=0; i<n; ++i)
y[i]=in();
ll ans=(1LL<<41)-1;
for(int i=40; i>=0; --i)
if(can(ans^(1LL<<i)))
ans^=1LL<<i;
out(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
552 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
644 KB |
Output is correct |
9 |
Correct |
2 ms |
700 KB |
Output is correct |
10 |
Correct |
3 ms |
712 KB |
Output is correct |
11 |
Correct |
2 ms |
712 KB |
Output is correct |
12 |
Correct |
2 ms |
712 KB |
Output is correct |
13 |
Correct |
2 ms |
792 KB |
Output is correct |
14 |
Correct |
2 ms |
876 KB |
Output is correct |
15 |
Correct |
2 ms |
896 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
3 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
1020 KB |
Output is correct |
19 |
Correct |
2 ms |
1020 KB |
Output is correct |
20 |
Correct |
2 ms |
1020 KB |
Output is correct |
21 |
Correct |
3 ms |
1020 KB |
Output is correct |
22 |
Correct |
2 ms |
1020 KB |
Output is correct |
23 |
Correct |
3 ms |
1020 KB |
Output is correct |
24 |
Correct |
2 ms |
1020 KB |
Output is correct |
25 |
Correct |
2 ms |
1068 KB |
Output is correct |
26 |
Correct |
3 ms |
1068 KB |
Output is correct |
27 |
Correct |
2 ms |
1068 KB |
Output is correct |
28 |
Correct |
2 ms |
1068 KB |
Output is correct |
29 |
Correct |
2 ms |
1068 KB |
Output is correct |
30 |
Correct |
2 ms |
1068 KB |
Output is correct |
31 |
Correct |
2 ms |
1068 KB |
Output is correct |
32 |
Correct |
2 ms |
1068 KB |
Output is correct |
33 |
Correct |
2 ms |
1068 KB |
Output is correct |
34 |
Correct |
2 ms |
1068 KB |
Output is correct |
35 |
Correct |
3 ms |
1068 KB |
Output is correct |
36 |
Correct |
2 ms |
1068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1068 KB |
Output is correct |
2 |
Correct |
2 ms |
1068 KB |
Output is correct |
3 |
Correct |
2 ms |
1068 KB |
Output is correct |
4 |
Correct |
2 ms |
1068 KB |
Output is correct |
5 |
Correct |
2 ms |
1068 KB |
Output is correct |
6 |
Correct |
2 ms |
1068 KB |
Output is correct |
7 |
Correct |
2 ms |
1068 KB |
Output is correct |
8 |
Correct |
2 ms |
1068 KB |
Output is correct |
9 |
Correct |
2 ms |
1068 KB |
Output is correct |
10 |
Correct |
2 ms |
1068 KB |
Output is correct |
11 |
Correct |
2 ms |
1068 KB |
Output is correct |
12 |
Correct |
2 ms |
1068 KB |
Output is correct |
13 |
Correct |
2 ms |
1068 KB |
Output is correct |
14 |
Correct |
2 ms |
1068 KB |
Output is correct |
15 |
Correct |
2 ms |
1068 KB |
Output is correct |
16 |
Correct |
2 ms |
1124 KB |
Output is correct |
17 |
Correct |
2 ms |
1132 KB |
Output is correct |
18 |
Correct |
2 ms |
1132 KB |
Output is correct |
19 |
Correct |
2 ms |
1192 KB |
Output is correct |
20 |
Correct |
3 ms |
1192 KB |
Output is correct |
21 |
Correct |
2 ms |
1192 KB |
Output is correct |
22 |
Correct |
3 ms |
1192 KB |
Output is correct |
23 |
Correct |
2 ms |
1192 KB |
Output is correct |
24 |
Correct |
2 ms |
1192 KB |
Output is correct |
25 |
Correct |
2 ms |
1216 KB |
Output is correct |
26 |
Correct |
3 ms |
1216 KB |
Output is correct |
27 |
Correct |
2 ms |
1216 KB |
Output is correct |
28 |
Correct |
2 ms |
1216 KB |
Output is correct |
29 |
Correct |
2 ms |
1216 KB |
Output is correct |
30 |
Correct |
2 ms |
1216 KB |
Output is correct |
31 |
Correct |
2 ms |
1216 KB |
Output is correct |
32 |
Correct |
2 ms |
1216 KB |
Output is correct |
33 |
Correct |
2 ms |
1216 KB |
Output is correct |
34 |
Correct |
2 ms |
1252 KB |
Output is correct |
35 |
Correct |
2 ms |
1252 KB |
Output is correct |
36 |
Correct |
2 ms |
1252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1424 KB |
Output is correct |
2 |
Correct |
2 ms |
1424 KB |
Output is correct |
3 |
Correct |
2 ms |
1424 KB |
Output is correct |
4 |
Correct |
3 ms |
1424 KB |
Output is correct |
5 |
Correct |
2 ms |
1424 KB |
Output is correct |
6 |
Correct |
2 ms |
1448 KB |
Output is correct |
7 |
Correct |
2 ms |
1456 KB |
Output is correct |
8 |
Correct |
2 ms |
1456 KB |
Output is correct |
9 |
Correct |
2 ms |
1456 KB |
Output is correct |
10 |
Correct |
2 ms |
1456 KB |
Output is correct |
11 |
Correct |
2 ms |
1456 KB |
Output is correct |
12 |
Correct |
2 ms |
1456 KB |
Output is correct |
13 |
Correct |
2 ms |
1456 KB |
Output is correct |
14 |
Correct |
2 ms |
1456 KB |
Output is correct |
15 |
Correct |
2 ms |
1456 KB |
Output is correct |
16 |
Correct |
3 ms |
1492 KB |
Output is correct |
17 |
Correct |
3 ms |
1492 KB |
Output is correct |
18 |
Correct |
3 ms |
1492 KB |
Output is correct |
19 |
Correct |
3 ms |
1492 KB |
Output is correct |
20 |
Correct |
3 ms |
1492 KB |
Output is correct |
21 |
Correct |
2 ms |
1492 KB |
Output is correct |
22 |
Correct |
3 ms |
1492 KB |
Output is correct |
23 |
Correct |
2 ms |
1492 KB |
Output is correct |
24 |
Correct |
2 ms |
1492 KB |
Output is correct |
25 |
Correct |
2 ms |
1492 KB |
Output is correct |
26 |
Correct |
2 ms |
1492 KB |
Output is correct |
27 |
Correct |
3 ms |
1492 KB |
Output is correct |
28 |
Correct |
3 ms |
1492 KB |
Output is correct |
29 |
Correct |
3 ms |
1492 KB |
Output is correct |
30 |
Correct |
4 ms |
1492 KB |
Output is correct |
31 |
Correct |
3 ms |
1492 KB |
Output is correct |
32 |
Correct |
4 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1492 KB |
Output is correct |
2 |
Correct |
2 ms |
1564 KB |
Output is correct |
3 |
Correct |
2 ms |
1572 KB |
Output is correct |
4 |
Correct |
2 ms |
1572 KB |
Output is correct |
5 |
Correct |
3 ms |
1572 KB |
Output is correct |
6 |
Correct |
2 ms |
1572 KB |
Output is correct |
7 |
Correct |
2 ms |
1572 KB |
Output is correct |
8 |
Correct |
5 ms |
1572 KB |
Output is correct |
9 |
Correct |
2 ms |
1572 KB |
Output is correct |
10 |
Correct |
2 ms |
1572 KB |
Output is correct |
11 |
Correct |
2 ms |
1572 KB |
Output is correct |
12 |
Correct |
2 ms |
1572 KB |
Output is correct |
13 |
Correct |
3 ms |
1572 KB |
Output is correct |
14 |
Correct |
3 ms |
1620 KB |
Output is correct |
15 |
Correct |
2 ms |
1620 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
3 ms |
1620 KB |
Output is correct |
18 |
Correct |
2 ms |
1620 KB |
Output is correct |
19 |
Correct |
3 ms |
1620 KB |
Output is correct |
20 |
Correct |
2 ms |
1620 KB |
Output is correct |
21 |
Correct |
2 ms |
1620 KB |
Output is correct |
22 |
Correct |
2 ms |
1620 KB |
Output is correct |
23 |
Correct |
3 ms |
1620 KB |
Output is correct |
24 |
Correct |
2 ms |
1620 KB |
Output is correct |
25 |
Correct |
4 ms |
1620 KB |
Output is correct |
26 |
Correct |
2 ms |
1620 KB |
Output is correct |
27 |
Correct |
2 ms |
1620 KB |
Output is correct |
28 |
Correct |
2 ms |
1620 KB |
Output is correct |
29 |
Correct |
3 ms |
1620 KB |
Output is correct |
30 |
Correct |
2 ms |
1620 KB |
Output is correct |
31 |
Correct |
2 ms |
1620 KB |
Output is correct |
32 |
Correct |
2 ms |
1620 KB |
Output is correct |
33 |
Correct |
3 ms |
1620 KB |
Output is correct |
34 |
Correct |
2 ms |
1620 KB |
Output is correct |
35 |
Correct |
2 ms |
1620 KB |
Output is correct |
36 |
Correct |
17 ms |
1620 KB |
Output is correct |
37 |
Correct |
2 ms |
1620 KB |
Output is correct |
38 |
Correct |
2 ms |
1620 KB |
Output is correct |
39 |
Correct |
2 ms |
1624 KB |
Output is correct |
40 |
Correct |
3 ms |
1628 KB |
Output is correct |
41 |
Correct |
3 ms |
1632 KB |
Output is correct |
42 |
Correct |
2 ms |
1636 KB |
Output is correct |
43 |
Correct |
2 ms |
1672 KB |
Output is correct |
44 |
Correct |
2 ms |
1672 KB |
Output is correct |
45 |
Correct |
3 ms |
1672 KB |
Output is correct |
46 |
Correct |
2 ms |
1716 KB |
Output is correct |
47 |
Correct |
2 ms |
1716 KB |
Output is correct |
48 |
Correct |
2 ms |
1716 KB |
Output is correct |
49 |
Correct |
2 ms |
1716 KB |
Output is correct |
50 |
Correct |
3 ms |
1716 KB |
Output is correct |
51 |
Correct |
2 ms |
1832 KB |
Output is correct |
52 |
Correct |
2 ms |
1832 KB |
Output is correct |
53 |
Correct |
3 ms |
1832 KB |
Output is correct |
54 |
Correct |
3 ms |
1832 KB |
Output is correct |
55 |
Correct |
3 ms |
1832 KB |
Output is correct |
56 |
Correct |
2 ms |
1876 KB |
Output is correct |
57 |
Correct |
2 ms |
1876 KB |
Output is correct |
58 |
Correct |
2 ms |
1876 KB |
Output is correct |
59 |
Correct |
3 ms |
1876 KB |
Output is correct |
60 |
Correct |
2 ms |
1876 KB |
Output is correct |
61 |
Correct |
2 ms |
1876 KB |
Output is correct |
62 |
Correct |
3 ms |
1876 KB |
Output is correct |
63 |
Correct |
2 ms |
1876 KB |
Output is correct |
64 |
Correct |
14 ms |
2180 KB |
Output is correct |
65 |
Correct |
3 ms |
2180 KB |
Output is correct |
66 |
Correct |
3 ms |
2180 KB |
Output is correct |
67 |
Correct |
3 ms |
2180 KB |
Output is correct |
68 |
Correct |
4 ms |
2196 KB |
Output is correct |
69 |
Correct |
8 ms |
2224 KB |
Output is correct |
70 |
Correct |
6 ms |
2224 KB |
Output is correct |
71 |
Correct |
3 ms |
2224 KB |
Output is correct |
72 |
Correct |
10 ms |
2224 KB |
Output is correct |
73 |
Correct |
7 ms |
2280 KB |
Output is correct |
74 |
Correct |
7 ms |
2280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2280 KB |
Output is correct |
2 |
Correct |
2 ms |
2280 KB |
Output is correct |
3 |
Correct |
2 ms |
2280 KB |
Output is correct |
4 |
Correct |
2 ms |
2280 KB |
Output is correct |
5 |
Correct |
3 ms |
2280 KB |
Output is correct |
6 |
Correct |
2 ms |
2280 KB |
Output is correct |
7 |
Correct |
2 ms |
2280 KB |
Output is correct |
8 |
Correct |
2 ms |
2280 KB |
Output is correct |
9 |
Correct |
2 ms |
2280 KB |
Output is correct |
10 |
Correct |
2 ms |
2280 KB |
Output is correct |
11 |
Correct |
2 ms |
2280 KB |
Output is correct |
12 |
Correct |
3 ms |
2280 KB |
Output is correct |
13 |
Correct |
2 ms |
2280 KB |
Output is correct |
14 |
Correct |
2 ms |
2280 KB |
Output is correct |
15 |
Correct |
2 ms |
2280 KB |
Output is correct |
16 |
Correct |
2 ms |
2280 KB |
Output is correct |
17 |
Correct |
2 ms |
2280 KB |
Output is correct |
18 |
Correct |
2 ms |
2280 KB |
Output is correct |
19 |
Correct |
2 ms |
2280 KB |
Output is correct |
20 |
Correct |
2 ms |
2280 KB |
Output is correct |
21 |
Correct |
2 ms |
2280 KB |
Output is correct |
22 |
Correct |
2 ms |
2280 KB |
Output is correct |
23 |
Correct |
2 ms |
2280 KB |
Output is correct |
24 |
Correct |
2 ms |
2280 KB |
Output is correct |
25 |
Correct |
3 ms |
2280 KB |
Output is correct |
26 |
Correct |
2 ms |
2280 KB |
Output is correct |
27 |
Correct |
3 ms |
2280 KB |
Output is correct |
28 |
Correct |
3 ms |
2280 KB |
Output is correct |
29 |
Correct |
2 ms |
2280 KB |
Output is correct |
30 |
Correct |
3 ms |
2280 KB |
Output is correct |
31 |
Correct |
2 ms |
2280 KB |
Output is correct |
32 |
Correct |
2 ms |
2280 KB |
Output is correct |
33 |
Correct |
3 ms |
2280 KB |
Output is correct |
34 |
Correct |
2 ms |
2280 KB |
Output is correct |
35 |
Correct |
3 ms |
2280 KB |
Output is correct |
36 |
Correct |
3 ms |
2280 KB |
Output is correct |
37 |
Correct |
3 ms |
2280 KB |
Output is correct |
38 |
Correct |
3 ms |
2280 KB |
Output is correct |
39 |
Correct |
3 ms |
2280 KB |
Output is correct |
40 |
Correct |
3 ms |
2280 KB |
Output is correct |
41 |
Correct |
4 ms |
2280 KB |
Output is correct |
42 |
Correct |
4 ms |
2280 KB |
Output is correct |
43 |
Correct |
2 ms |
2280 KB |
Output is correct |
44 |
Correct |
3 ms |
2280 KB |
Output is correct |
45 |
Correct |
3 ms |
2280 KB |
Output is correct |
46 |
Correct |
3 ms |
2280 KB |
Output is correct |
47 |
Correct |
3 ms |
2280 KB |
Output is correct |
48 |
Correct |
3 ms |
2280 KB |
Output is correct |
49 |
Correct |
2 ms |
2280 KB |
Output is correct |
50 |
Correct |
3 ms |
2280 KB |
Output is correct |
51 |
Correct |
3 ms |
2280 KB |
Output is correct |
52 |
Correct |
12 ms |
2280 KB |
Output is correct |
53 |
Correct |
16 ms |
2280 KB |
Output is correct |
54 |
Correct |
30 ms |
2280 KB |
Output is correct |
55 |
Correct |
28 ms |
2280 KB |
Output is correct |
56 |
Correct |
95 ms |
2280 KB |
Output is correct |
57 |
Correct |
105 ms |
2280 KB |
Output is correct |
58 |
Correct |
84 ms |
2296 KB |
Output is correct |
59 |
Correct |
90 ms |
2316 KB |
Output is correct |
60 |
Correct |
98 ms |
2316 KB |
Output is correct |
61 |
Correct |
3 ms |
2316 KB |
Output is correct |
62 |
Correct |
20 ms |
2352 KB |
Output is correct |
63 |
Correct |
30 ms |
2456 KB |
Output is correct |
64 |
Correct |
25 ms |
2456 KB |
Output is correct |
65 |
Correct |
46 ms |
2456 KB |
Output is correct |
66 |
Correct |
70 ms |
2456 KB |
Output is correct |
67 |
Correct |
91 ms |
2456 KB |
Output is correct |
68 |
Correct |
104 ms |
2456 KB |
Output is correct |
69 |
Correct |
99 ms |
2504 KB |
Output is correct |