#include <bits/stdc++.h>
using namespace std;
int n,a,b;
long long y[2003],ans,o,memo1[2003];
bool memo[102][102],vis[102][102];
bool dp (int pos,int cnt)
{
if (pos==n)
{
if (cnt>=a&&cnt<=b)
return 1;
return 0;
}
if (vis[pos][cnt])
return memo[pos][cnt];
vis[pos][cnt]=true;
long long sum=0;
for (int i=pos;i<n;i++)
{
sum+=y[i];
bool flag=false;
for (long long j=40;(1LL<<j)>=o;j--)
{
if ((sum&(1LL<<j))>((ans&(1LL<<j))))
flag=true;
}
if (!flag)
memo[pos][cnt]|=dp(i+1,cnt+1);
}
return memo[pos][cnt];
}
long long dp1 (int pos)
{
if (pos==n)
return 0;
if (memo1[pos]!=-1)
return memo1[pos];
memo1[pos]=1e9;
long long sum=0;
for (int i=pos;i<n;i++)
{
sum+=y[i];
bool flag=false;
for (long long j=40;(1LL<<j)>=o;j--)
{
if ((sum&(1LL<<j))>((ans&(1LL<<j))))
flag=true;
}
if (!flag)
memo1[pos]=min(memo1[pos],dp1(i+1)+1);
}
return memo1[pos];
}
int main()
{
cin >>n>>a>>b;
for (int i=0;i<n;i++)
cin >>y[i];
if (a==1)
{
for (long long i=40;i>=0;i--)
{
memset(memo1,-1,sizeof memo1);
o=(1LL<<i);
if (dp1(0)>b)
ans|=o;
}
}
else
{
for (long long i=40;i>=0;i--)
{
memset(vis,0,sizeof vis);
memset(memo,0,sizeof memo);
o=(1LL<<i);
if (!dp(0,0))
ans|=o;
}
}
cout <<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
488 KB |
Output is correct |
6 |
Correct |
2 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
576 KB |
Output is correct |
8 |
Correct |
3 ms |
576 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
2 ms |
580 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
2 ms |
684 KB |
Output is correct |
14 |
Correct |
1 ms |
684 KB |
Output is correct |
15 |
Correct |
2 ms |
704 KB |
Output is correct |
16 |
Correct |
1 ms |
704 KB |
Output is correct |
17 |
Correct |
1 ms |
704 KB |
Output is correct |
18 |
Correct |
2 ms |
704 KB |
Output is correct |
19 |
Correct |
2 ms |
728 KB |
Output is correct |
20 |
Correct |
3 ms |
732 KB |
Output is correct |
21 |
Correct |
3 ms |
732 KB |
Output is correct |
22 |
Correct |
3 ms |
732 KB |
Output is correct |
23 |
Correct |
3 ms |
732 KB |
Output is correct |
24 |
Correct |
3 ms |
732 KB |
Output is correct |
25 |
Correct |
3 ms |
732 KB |
Output is correct |
26 |
Correct |
3 ms |
736 KB |
Output is correct |
27 |
Correct |
1 ms |
740 KB |
Output is correct |
28 |
Correct |
1 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
872 KB |
Output is correct |
30 |
Correct |
2 ms |
872 KB |
Output is correct |
31 |
Correct |
2 ms |
872 KB |
Output is correct |
32 |
Correct |
2 ms |
872 KB |
Output is correct |
33 |
Correct |
2 ms |
872 KB |
Output is correct |
34 |
Correct |
2 ms |
872 KB |
Output is correct |
35 |
Correct |
2 ms |
872 KB |
Output is correct |
36 |
Correct |
2 ms |
872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
872 KB |
Output is correct |
2 |
Correct |
1 ms |
872 KB |
Output is correct |
3 |
Correct |
2 ms |
872 KB |
Output is correct |
4 |
Correct |
2 ms |
872 KB |
Output is correct |
5 |
Correct |
1 ms |
872 KB |
Output is correct |
6 |
Correct |
2 ms |
872 KB |
Output is correct |
7 |
Correct |
2 ms |
872 KB |
Output is correct |
8 |
Correct |
2 ms |
872 KB |
Output is correct |
9 |
Correct |
2 ms |
872 KB |
Output is correct |
10 |
Correct |
2 ms |
920 KB |
Output is correct |
11 |
Correct |
2 ms |
920 KB |
Output is correct |
12 |
Correct |
2 ms |
920 KB |
Output is correct |
13 |
Correct |
2 ms |
920 KB |
Output is correct |
14 |
Correct |
1 ms |
920 KB |
Output is correct |
15 |
Correct |
1 ms |
920 KB |
Output is correct |
16 |
Correct |
2 ms |
920 KB |
Output is correct |
17 |
Correct |
1 ms |
920 KB |
Output is correct |
18 |
Correct |
2 ms |
920 KB |
Output is correct |
19 |
Correct |
2 ms |
920 KB |
Output is correct |
20 |
Correct |
3 ms |
920 KB |
Output is correct |
21 |
Correct |
5 ms |
920 KB |
Output is correct |
22 |
Correct |
5 ms |
920 KB |
Output is correct |
23 |
Correct |
5 ms |
920 KB |
Output is correct |
24 |
Correct |
3 ms |
920 KB |
Output is correct |
25 |
Correct |
4 ms |
956 KB |
Output is correct |
26 |
Correct |
5 ms |
956 KB |
Output is correct |
27 |
Correct |
2 ms |
956 KB |
Output is correct |
28 |
Correct |
2 ms |
968 KB |
Output is correct |
29 |
Correct |
3 ms |
972 KB |
Output is correct |
30 |
Correct |
3 ms |
972 KB |
Output is correct |
31 |
Correct |
3 ms |
972 KB |
Output is correct |
32 |
Correct |
3 ms |
972 KB |
Output is correct |
33 |
Correct |
3 ms |
972 KB |
Output is correct |
34 |
Correct |
3 ms |
972 KB |
Output is correct |
35 |
Correct |
4 ms |
972 KB |
Output is correct |
36 |
Correct |
3 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
2 ms |
972 KB |
Output is correct |
6 |
Correct |
2 ms |
972 KB |
Output is correct |
7 |
Correct |
2 ms |
972 KB |
Output is correct |
8 |
Correct |
2 ms |
972 KB |
Output is correct |
9 |
Correct |
2 ms |
1012 KB |
Output is correct |
10 |
Correct |
2 ms |
1012 KB |
Output is correct |
11 |
Correct |
2 ms |
1012 KB |
Output is correct |
12 |
Correct |
2 ms |
1012 KB |
Output is correct |
13 |
Correct |
2 ms |
1012 KB |
Output is correct |
14 |
Correct |
2 ms |
1012 KB |
Output is correct |
15 |
Correct |
2 ms |
1012 KB |
Output is correct |
16 |
Correct |
2 ms |
1012 KB |
Output is correct |
17 |
Correct |
3 ms |
1012 KB |
Output is correct |
18 |
Correct |
4 ms |
1012 KB |
Output is correct |
19 |
Correct |
3 ms |
1012 KB |
Output is correct |
20 |
Correct |
3 ms |
1012 KB |
Output is correct |
21 |
Correct |
3 ms |
1012 KB |
Output is correct |
22 |
Correct |
3 ms |
1012 KB |
Output is correct |
23 |
Correct |
4 ms |
1012 KB |
Output is correct |
24 |
Correct |
4 ms |
1012 KB |
Output is correct |
25 |
Correct |
5 ms |
1012 KB |
Output is correct |
26 |
Correct |
6 ms |
1012 KB |
Output is correct |
27 |
Correct |
7 ms |
1012 KB |
Output is correct |
28 |
Correct |
8 ms |
1012 KB |
Output is correct |
29 |
Correct |
8 ms |
1012 KB |
Output is correct |
30 |
Correct |
8 ms |
1012 KB |
Output is correct |
31 |
Correct |
7 ms |
1012 KB |
Output is correct |
32 |
Correct |
8 ms |
1012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1012 KB |
Output is correct |
2 |
Correct |
1 ms |
1012 KB |
Output is correct |
3 |
Correct |
2 ms |
1012 KB |
Output is correct |
4 |
Correct |
1 ms |
1012 KB |
Output is correct |
5 |
Correct |
2 ms |
1012 KB |
Output is correct |
6 |
Correct |
2 ms |
1012 KB |
Output is correct |
7 |
Correct |
2 ms |
1012 KB |
Output is correct |
8 |
Correct |
2 ms |
1012 KB |
Output is correct |
9 |
Correct |
2 ms |
1012 KB |
Output is correct |
10 |
Correct |
2 ms |
1012 KB |
Output is correct |
11 |
Correct |
2 ms |
1012 KB |
Output is correct |
12 |
Correct |
2 ms |
1012 KB |
Output is correct |
13 |
Correct |
2 ms |
1012 KB |
Output is correct |
14 |
Correct |
1 ms |
1012 KB |
Output is correct |
15 |
Correct |
1 ms |
1012 KB |
Output is correct |
16 |
Correct |
1 ms |
1012 KB |
Output is correct |
17 |
Correct |
2 ms |
1012 KB |
Output is correct |
18 |
Correct |
2 ms |
1012 KB |
Output is correct |
19 |
Correct |
3 ms |
1012 KB |
Output is correct |
20 |
Correct |
4 ms |
1012 KB |
Output is correct |
21 |
Correct |
5 ms |
1012 KB |
Output is correct |
22 |
Correct |
4 ms |
1056 KB |
Output is correct |
23 |
Correct |
4 ms |
1056 KB |
Output is correct |
24 |
Correct |
3 ms |
1056 KB |
Output is correct |
25 |
Correct |
3 ms |
1056 KB |
Output is correct |
26 |
Correct |
3 ms |
1056 KB |
Output is correct |
27 |
Correct |
1 ms |
1056 KB |
Output is correct |
28 |
Correct |
2 ms |
1056 KB |
Output is correct |
29 |
Correct |
2 ms |
1056 KB |
Output is correct |
30 |
Correct |
2 ms |
1056 KB |
Output is correct |
31 |
Correct |
2 ms |
1056 KB |
Output is correct |
32 |
Correct |
2 ms |
1056 KB |
Output is correct |
33 |
Correct |
2 ms |
1056 KB |
Output is correct |
34 |
Correct |
2 ms |
1056 KB |
Output is correct |
35 |
Correct |
2 ms |
1056 KB |
Output is correct |
36 |
Correct |
2 ms |
1056 KB |
Output is correct |
37 |
Correct |
2 ms |
1056 KB |
Output is correct |
38 |
Correct |
2 ms |
1056 KB |
Output is correct |
39 |
Correct |
3 ms |
1056 KB |
Output is correct |
40 |
Correct |
4 ms |
1056 KB |
Output is correct |
41 |
Correct |
4 ms |
1116 KB |
Output is correct |
42 |
Correct |
4 ms |
1116 KB |
Output is correct |
43 |
Correct |
5 ms |
1116 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
3 ms |
1128 KB |
Output is correct |
46 |
Correct |
4 ms |
1128 KB |
Output is correct |
47 |
Correct |
3 ms |
1128 KB |
Output is correct |
48 |
Correct |
6 ms |
1128 KB |
Output is correct |
49 |
Correct |
6 ms |
1128 KB |
Output is correct |
50 |
Correct |
7 ms |
1128 KB |
Output is correct |
51 |
Correct |
8 ms |
1128 KB |
Output is correct |
52 |
Correct |
9 ms |
1128 KB |
Output is correct |
53 |
Correct |
8 ms |
1128 KB |
Output is correct |
54 |
Correct |
8 ms |
1128 KB |
Output is correct |
55 |
Correct |
7 ms |
1128 KB |
Output is correct |
56 |
Correct |
2 ms |
1128 KB |
Output is correct |
57 |
Correct |
4 ms |
1128 KB |
Output is correct |
58 |
Correct |
2 ms |
1128 KB |
Output is correct |
59 |
Correct |
3 ms |
1128 KB |
Output is correct |
60 |
Correct |
8 ms |
1128 KB |
Output is correct |
61 |
Correct |
4 ms |
1128 KB |
Output is correct |
62 |
Correct |
4 ms |
1128 KB |
Output is correct |
63 |
Correct |
4 ms |
1128 KB |
Output is correct |
64 |
Correct |
184 ms |
1232 KB |
Output is correct |
65 |
Correct |
6 ms |
1232 KB |
Output is correct |
66 |
Correct |
13 ms |
1232 KB |
Output is correct |
67 |
Correct |
15 ms |
1232 KB |
Output is correct |
68 |
Correct |
25 ms |
1232 KB |
Output is correct |
69 |
Correct |
24 ms |
1232 KB |
Output is correct |
70 |
Correct |
25 ms |
1256 KB |
Output is correct |
71 |
Correct |
30 ms |
1256 KB |
Output is correct |
72 |
Correct |
50 ms |
1256 KB |
Output is correct |
73 |
Correct |
47 ms |
1256 KB |
Output is correct |
74 |
Correct |
48 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1272 KB |
Output is correct |
2 |
Correct |
1 ms |
1272 KB |
Output is correct |
3 |
Correct |
1 ms |
1272 KB |
Output is correct |
4 |
Correct |
2 ms |
1272 KB |
Output is correct |
5 |
Correct |
2 ms |
1272 KB |
Output is correct |
6 |
Correct |
2 ms |
1272 KB |
Output is correct |
7 |
Correct |
2 ms |
1272 KB |
Output is correct |
8 |
Correct |
2 ms |
1272 KB |
Output is correct |
9 |
Correct |
2 ms |
1272 KB |
Output is correct |
10 |
Correct |
2 ms |
1272 KB |
Output is correct |
11 |
Correct |
2 ms |
1272 KB |
Output is correct |
12 |
Correct |
2 ms |
1272 KB |
Output is correct |
13 |
Correct |
2 ms |
1272 KB |
Output is correct |
14 |
Correct |
1 ms |
1272 KB |
Output is correct |
15 |
Correct |
2 ms |
1272 KB |
Output is correct |
16 |
Correct |
1 ms |
1272 KB |
Output is correct |
17 |
Correct |
2 ms |
1272 KB |
Output is correct |
18 |
Correct |
2 ms |
1272 KB |
Output is correct |
19 |
Correct |
1 ms |
1272 KB |
Output is correct |
20 |
Correct |
2 ms |
1272 KB |
Output is correct |
21 |
Correct |
2 ms |
1272 KB |
Output is correct |
22 |
Correct |
2 ms |
1272 KB |
Output is correct |
23 |
Correct |
2 ms |
1272 KB |
Output is correct |
24 |
Correct |
2 ms |
1272 KB |
Output is correct |
25 |
Correct |
2 ms |
1272 KB |
Output is correct |
26 |
Correct |
3 ms |
1272 KB |
Output is correct |
27 |
Correct |
2 ms |
1272 KB |
Output is correct |
28 |
Correct |
3 ms |
1272 KB |
Output is correct |
29 |
Correct |
3 ms |
1272 KB |
Output is correct |
30 |
Correct |
3 ms |
1272 KB |
Output is correct |
31 |
Correct |
3 ms |
1272 KB |
Output is correct |
32 |
Correct |
3 ms |
1272 KB |
Output is correct |
33 |
Correct |
3 ms |
1272 KB |
Output is correct |
34 |
Correct |
4 ms |
1272 KB |
Output is correct |
35 |
Correct |
4 ms |
1272 KB |
Output is correct |
36 |
Correct |
5 ms |
1272 KB |
Output is correct |
37 |
Correct |
6 ms |
1272 KB |
Output is correct |
38 |
Correct |
7 ms |
1272 KB |
Output is correct |
39 |
Correct |
8 ms |
1272 KB |
Output is correct |
40 |
Correct |
11 ms |
1272 KB |
Output is correct |
41 |
Correct |
7 ms |
1272 KB |
Output is correct |
42 |
Correct |
7 ms |
1272 KB |
Output is correct |
43 |
Correct |
2 ms |
1272 KB |
Output is correct |
44 |
Correct |
5 ms |
1272 KB |
Output is correct |
45 |
Correct |
3 ms |
1272 KB |
Output is correct |
46 |
Correct |
3 ms |
1272 KB |
Output is correct |
47 |
Correct |
6 ms |
1272 KB |
Output is correct |
48 |
Correct |
3 ms |
1272 KB |
Output is correct |
49 |
Correct |
5 ms |
1272 KB |
Output is correct |
50 |
Correct |
5 ms |
1272 KB |
Output is correct |
51 |
Correct |
4 ms |
1272 KB |
Output is correct |
52 |
Correct |
132 ms |
1276 KB |
Output is correct |
53 |
Correct |
41 ms |
1276 KB |
Output is correct |
54 |
Correct |
601 ms |
1276 KB |
Output is correct |
55 |
Correct |
344 ms |
1276 KB |
Output is correct |
56 |
Correct |
462 ms |
1404 KB |
Output is correct |
57 |
Correct |
312 ms |
1404 KB |
Output is correct |
58 |
Correct |
812 ms |
1404 KB |
Output is correct |
59 |
Execution timed out |
1067 ms |
1404 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |