#include <bits/stdc++.h>
#define maxn 2005
using namespace std;
int n,a,b;
long long s[maxn];
bool moze(int x)
{
int g=0;
int pr=0;
long long tr=1LL<<x;
for(int i=1;i<=n;i++)
{
if(s[i]-s[pr]>=tr)
{
if(i==pr+1)return false;
g++;
pr=i-1;
i--;
}
else if(i==n)g++;
}
if(g<=b)return true;
return false;
}
int numbit()
{
int l=0;
int r=50;
int sol;
while(l<=r)
{
int mid=(l+r)/2;
if(moze(mid))
{
sol=mid;
r=mid-1;
}
else l=mid+1;
}
return sol;
}
bool t[maxn][maxn];
bool exist(long long br0,int numb)
{
long long br=1LL<<numb;
for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)t[i][j]=false;
t[0][0]=true;
for(int i=1;i<=n;i++)
for(int j=0;j<i;j++)
{
if(((s[i]-s[j])&br0)==0LL && (s[i]-s[j])<br)
{
for(int k=0;k<=n-1;k++)if(t[j][k])t[i][k+1]=true;
}
}
for(int i=a;i<=b;i++)if(t[n][i])return true;
return false;
}
int dp2[maxn];
bool exist2(long long br0,int numb)
{
long long br=1LL<<numb;
for(int i=1;i<=n;i++)dp2[i]=b+1;
dp2[0]=0;
for(int i=1;i<=n;i++)
for(int j=0;j<i;j++)
{
if(((s[i]-s[j])&br0)==0LL && (s[i]-s[j])<br && dp2[j]+1<dp2[i])
{
dp2[i]=dp2[j]+1;
}
}
return dp2[n]<=b;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>a>>b;s[0]=0LL;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
s[i]=s[i-1]+x;
}
int br=numbit();
if(br==0)
{
cout<<0<<endl;
return 0;
}
long long sol=1LL<<(br-1);
long long obr=0;
if(a==1)
{
for(int i=br-2;i>=0;i--)
{
obr+=1LL<<i;
if(!exist2(obr,br))
{
obr-=1LL<<i;
sol+=1LL<<i;
}
}
cout<<sol<<endl;
return 0;
}
for(int i=br-2;i>=0;i--)
{
obr+=1LL<<i;
if(!exist(obr,br))
{
obr-=1LL<<i;
sol+=1LL<<i;
}
}
cout<<sol<<endl;
return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp: In function 'int numbit()':
sculpture.cpp:42:12: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
return sol;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
456 KB |
Output is correct |
4 |
Correct |
2 ms |
532 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
692 KB |
Output is correct |
10 |
Correct |
2 ms |
692 KB |
Output is correct |
11 |
Correct |
2 ms |
692 KB |
Output is correct |
12 |
Correct |
2 ms |
692 KB |
Output is correct |
13 |
Correct |
2 ms |
692 KB |
Output is correct |
14 |
Correct |
2 ms |
692 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
2 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
2 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
2 ms |
724 KB |
Output is correct |
23 |
Correct |
2 ms |
724 KB |
Output is correct |
24 |
Correct |
2 ms |
724 KB |
Output is correct |
25 |
Correct |
2 ms |
724 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
2 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
724 KB |
Output is correct |
29 |
Correct |
2 ms |
724 KB |
Output is correct |
30 |
Correct |
2 ms |
724 KB |
Output is correct |
31 |
Correct |
2 ms |
724 KB |
Output is correct |
32 |
Correct |
2 ms |
724 KB |
Output is correct |
33 |
Correct |
2 ms |
752 KB |
Output is correct |
34 |
Correct |
2 ms |
752 KB |
Output is correct |
35 |
Correct |
2 ms |
752 KB |
Output is correct |
36 |
Correct |
2 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
752 KB |
Output is correct |
2 |
Correct |
2 ms |
752 KB |
Output is correct |
3 |
Correct |
3 ms |
752 KB |
Output is correct |
4 |
Correct |
2 ms |
752 KB |
Output is correct |
5 |
Correct |
2 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
752 KB |
Output is correct |
8 |
Correct |
2 ms |
752 KB |
Output is correct |
9 |
Correct |
2 ms |
752 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
752 KB |
Output is correct |
12 |
Correct |
2 ms |
752 KB |
Output is correct |
13 |
Correct |
2 ms |
752 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
752 KB |
Output is correct |
16 |
Correct |
2 ms |
752 KB |
Output is correct |
17 |
Correct |
2 ms |
752 KB |
Output is correct |
18 |
Correct |
2 ms |
752 KB |
Output is correct |
19 |
Correct |
2 ms |
752 KB |
Output is correct |
20 |
Correct |
2 ms |
752 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
752 KB |
Output is correct |
23 |
Correct |
3 ms |
752 KB |
Output is correct |
24 |
Correct |
2 ms |
752 KB |
Output is correct |
25 |
Correct |
2 ms |
752 KB |
Output is correct |
26 |
Correct |
2 ms |
752 KB |
Output is correct |
27 |
Correct |
2 ms |
752 KB |
Output is correct |
28 |
Correct |
2 ms |
752 KB |
Output is correct |
29 |
Correct |
2 ms |
752 KB |
Output is correct |
30 |
Correct |
2 ms |
752 KB |
Output is correct |
31 |
Correct |
2 ms |
752 KB |
Output is correct |
32 |
Correct |
2 ms |
752 KB |
Output is correct |
33 |
Correct |
2 ms |
752 KB |
Output is correct |
34 |
Correct |
2 ms |
752 KB |
Output is correct |
35 |
Correct |
2 ms |
752 KB |
Output is correct |
36 |
Correct |
2 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
752 KB |
Output is correct |
2 |
Correct |
2 ms |
752 KB |
Output is correct |
3 |
Correct |
2 ms |
752 KB |
Output is correct |
4 |
Correct |
2 ms |
752 KB |
Output is correct |
5 |
Correct |
2 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
752 KB |
Output is correct |
8 |
Correct |
2 ms |
752 KB |
Output is correct |
9 |
Correct |
3 ms |
752 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
752 KB |
Output is correct |
12 |
Correct |
2 ms |
752 KB |
Output is correct |
13 |
Correct |
2 ms |
752 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
752 KB |
Output is correct |
16 |
Correct |
2 ms |
752 KB |
Output is correct |
17 |
Correct |
2 ms |
752 KB |
Output is correct |
18 |
Correct |
2 ms |
752 KB |
Output is correct |
19 |
Correct |
2 ms |
752 KB |
Output is correct |
20 |
Correct |
2 ms |
752 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
752 KB |
Output is correct |
23 |
Correct |
2 ms |
752 KB |
Output is correct |
24 |
Correct |
2 ms |
752 KB |
Output is correct |
25 |
Correct |
2 ms |
752 KB |
Output is correct |
26 |
Correct |
2 ms |
752 KB |
Output is correct |
27 |
Correct |
2 ms |
752 KB |
Output is correct |
28 |
Correct |
2 ms |
752 KB |
Output is correct |
29 |
Correct |
2 ms |
752 KB |
Output is correct |
30 |
Correct |
2 ms |
752 KB |
Output is correct |
31 |
Correct |
2 ms |
752 KB |
Output is correct |
32 |
Correct |
2 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
752 KB |
Output is correct |
2 |
Correct |
2 ms |
752 KB |
Output is correct |
3 |
Correct |
2 ms |
752 KB |
Output is correct |
4 |
Correct |
2 ms |
752 KB |
Output is correct |
5 |
Correct |
2 ms |
752 KB |
Output is correct |
6 |
Correct |
2 ms |
752 KB |
Output is correct |
7 |
Correct |
2 ms |
752 KB |
Output is correct |
8 |
Correct |
2 ms |
752 KB |
Output is correct |
9 |
Correct |
2 ms |
752 KB |
Output is correct |
10 |
Correct |
2 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
752 KB |
Output is correct |
12 |
Correct |
2 ms |
752 KB |
Output is correct |
13 |
Correct |
2 ms |
752 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
752 KB |
Output is correct |
16 |
Correct |
2 ms |
752 KB |
Output is correct |
17 |
Correct |
2 ms |
752 KB |
Output is correct |
18 |
Correct |
2 ms |
752 KB |
Output is correct |
19 |
Correct |
2 ms |
752 KB |
Output is correct |
20 |
Correct |
2 ms |
752 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Correct |
2 ms |
752 KB |
Output is correct |
23 |
Correct |
2 ms |
752 KB |
Output is correct |
24 |
Correct |
2 ms |
752 KB |
Output is correct |
25 |
Correct |
2 ms |
752 KB |
Output is correct |
26 |
Correct |
2 ms |
752 KB |
Output is correct |
27 |
Correct |
3 ms |
752 KB |
Output is correct |
28 |
Correct |
2 ms |
752 KB |
Output is correct |
29 |
Correct |
2 ms |
752 KB |
Output is correct |
30 |
Correct |
2 ms |
752 KB |
Output is correct |
31 |
Correct |
2 ms |
752 KB |
Output is correct |
32 |
Correct |
2 ms |
752 KB |
Output is correct |
33 |
Correct |
2 ms |
752 KB |
Output is correct |
34 |
Correct |
2 ms |
752 KB |
Output is correct |
35 |
Correct |
2 ms |
752 KB |
Output is correct |
36 |
Correct |
3 ms |
752 KB |
Output is correct |
37 |
Correct |
2 ms |
752 KB |
Output is correct |
38 |
Correct |
2 ms |
752 KB |
Output is correct |
39 |
Correct |
2 ms |
752 KB |
Output is correct |
40 |
Correct |
2 ms |
752 KB |
Output is correct |
41 |
Correct |
2 ms |
752 KB |
Output is correct |
42 |
Correct |
2 ms |
752 KB |
Output is correct |
43 |
Correct |
2 ms |
752 KB |
Output is correct |
44 |
Correct |
2 ms |
752 KB |
Output is correct |
45 |
Correct |
2 ms |
752 KB |
Output is correct |
46 |
Correct |
2 ms |
752 KB |
Output is correct |
47 |
Correct |
2 ms |
752 KB |
Output is correct |
48 |
Correct |
2 ms |
752 KB |
Output is correct |
49 |
Correct |
2 ms |
752 KB |
Output is correct |
50 |
Correct |
2 ms |
752 KB |
Output is correct |
51 |
Correct |
3 ms |
752 KB |
Output is correct |
52 |
Correct |
2 ms |
752 KB |
Output is correct |
53 |
Correct |
2 ms |
752 KB |
Output is correct |
54 |
Correct |
3 ms |
752 KB |
Output is correct |
55 |
Correct |
2 ms |
752 KB |
Output is correct |
56 |
Correct |
2 ms |
752 KB |
Output is correct |
57 |
Correct |
3 ms |
752 KB |
Output is correct |
58 |
Correct |
3 ms |
752 KB |
Output is correct |
59 |
Correct |
3 ms |
752 KB |
Output is correct |
60 |
Correct |
2 ms |
752 KB |
Output is correct |
61 |
Correct |
2 ms |
752 KB |
Output is correct |
62 |
Correct |
3 ms |
752 KB |
Output is correct |
63 |
Correct |
3 ms |
752 KB |
Output is correct |
64 |
Correct |
2 ms |
752 KB |
Output is correct |
65 |
Correct |
3 ms |
752 KB |
Output is correct |
66 |
Correct |
3 ms |
764 KB |
Output is correct |
67 |
Correct |
3 ms |
764 KB |
Output is correct |
68 |
Correct |
3 ms |
764 KB |
Output is correct |
69 |
Correct |
3 ms |
764 KB |
Output is correct |
70 |
Correct |
3 ms |
804 KB |
Output is correct |
71 |
Correct |
4 ms |
804 KB |
Output is correct |
72 |
Correct |
5 ms |
804 KB |
Output is correct |
73 |
Correct |
4 ms |
804 KB |
Output is correct |
74 |
Correct |
4 ms |
808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
808 KB |
Output is correct |
2 |
Correct |
2 ms |
808 KB |
Output is correct |
3 |
Correct |
2 ms |
808 KB |
Output is correct |
4 |
Correct |
2 ms |
808 KB |
Output is correct |
5 |
Correct |
2 ms |
808 KB |
Output is correct |
6 |
Correct |
2 ms |
808 KB |
Output is correct |
7 |
Correct |
2 ms |
808 KB |
Output is correct |
8 |
Correct |
2 ms |
808 KB |
Output is correct |
9 |
Correct |
2 ms |
808 KB |
Output is correct |
10 |
Correct |
2 ms |
808 KB |
Output is correct |
11 |
Correct |
2 ms |
808 KB |
Output is correct |
12 |
Correct |
2 ms |
808 KB |
Output is correct |
13 |
Correct |
2 ms |
808 KB |
Output is correct |
14 |
Correct |
2 ms |
808 KB |
Output is correct |
15 |
Correct |
2 ms |
808 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
2 ms |
808 KB |
Output is correct |
18 |
Correct |
2 ms |
808 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
2 ms |
808 KB |
Output is correct |
21 |
Correct |
2 ms |
808 KB |
Output is correct |
22 |
Correct |
2 ms |
808 KB |
Output is correct |
23 |
Correct |
2 ms |
808 KB |
Output is correct |
24 |
Correct |
2 ms |
808 KB |
Output is correct |
25 |
Correct |
2 ms |
808 KB |
Output is correct |
26 |
Correct |
2 ms |
808 KB |
Output is correct |
27 |
Correct |
2 ms |
808 KB |
Output is correct |
28 |
Correct |
2 ms |
808 KB |
Output is correct |
29 |
Correct |
2 ms |
808 KB |
Output is correct |
30 |
Correct |
2 ms |
808 KB |
Output is correct |
31 |
Correct |
2 ms |
808 KB |
Output is correct |
32 |
Correct |
2 ms |
808 KB |
Output is correct |
33 |
Correct |
2 ms |
808 KB |
Output is correct |
34 |
Correct |
2 ms |
808 KB |
Output is correct |
35 |
Correct |
2 ms |
808 KB |
Output is correct |
36 |
Correct |
3 ms |
808 KB |
Output is correct |
37 |
Correct |
2 ms |
808 KB |
Output is correct |
38 |
Correct |
2 ms |
808 KB |
Output is correct |
39 |
Correct |
2 ms |
808 KB |
Output is correct |
40 |
Correct |
2 ms |
808 KB |
Output is correct |
41 |
Correct |
2 ms |
808 KB |
Output is correct |
42 |
Correct |
2 ms |
808 KB |
Output is correct |
43 |
Correct |
2 ms |
808 KB |
Output is correct |
44 |
Correct |
3 ms |
808 KB |
Output is correct |
45 |
Correct |
3 ms |
808 KB |
Output is correct |
46 |
Correct |
3 ms |
808 KB |
Output is correct |
47 |
Correct |
3 ms |
808 KB |
Output is correct |
48 |
Correct |
3 ms |
808 KB |
Output is correct |
49 |
Correct |
3 ms |
808 KB |
Output is correct |
50 |
Correct |
3 ms |
808 KB |
Output is correct |
51 |
Correct |
2 ms |
808 KB |
Output is correct |
52 |
Correct |
21 ms |
808 KB |
Output is correct |
53 |
Correct |
50 ms |
808 KB |
Output is correct |
54 |
Correct |
38 ms |
808 KB |
Output is correct |
55 |
Correct |
29 ms |
808 KB |
Output is correct |
56 |
Correct |
364 ms |
808 KB |
Output is correct |
57 |
Correct |
343 ms |
808 KB |
Output is correct |
58 |
Correct |
108 ms |
808 KB |
Output is correct |
59 |
Correct |
111 ms |
808 KB |
Output is correct |
60 |
Correct |
69 ms |
808 KB |
Output is correct |
61 |
Correct |
3 ms |
808 KB |
Output is correct |
62 |
Correct |
49 ms |
808 KB |
Output is correct |
63 |
Correct |
47 ms |
808 KB |
Output is correct |
64 |
Correct |
85 ms |
808 KB |
Output is correct |
65 |
Correct |
127 ms |
808 KB |
Output is correct |
66 |
Correct |
251 ms |
816 KB |
Output is correct |
67 |
Correct |
58 ms |
816 KB |
Output is correct |
68 |
Correct |
257 ms |
856 KB |
Output is correct |
69 |
Correct |
322 ms |
876 KB |
Output is correct |