#include<bits/stdc++.h>
using namespace std;
#define try ico
#define ll long long
const ll MAXN=2048;
ll y[MAXN],n,a,b;
ll depth[MAXN];
bool dp[MAXN][MAXN];
bool try(ll mask)
{
memset(dp,0,sizeof(dp));
dp[1][0]=1;
for(int i=1;i<=n;i++)
{
ll sum=0;
for(int j=i;j<=n;j++)
{
sum+=y[j];
if((mask&sum)==sum&&(mask|sum)==mask)
{
for(int l=0;l<=n;l++)
{
dp[j+1][l+1]|=dp[i][l];
}
}
}
}
for(ll i=a;i<=b;i++)
{
if(dp[n+1][i])
{
return 1;
}
}
return 0;
}
bool try1(ll mask)
{
queue<ll>q;
q.push(1);
depth[1]=0;
for(int i=2;i<=n;i++)depth[i]=n+200;
while(!q.empty())
{
ll u=q.front();q.pop();
ll sum=0;
for(int j=u;j<=n;j++)
{
sum+=y[j];
if((mask&sum)==sum&&(mask|sum)==mask)
{
if(depth[j+1]<=depth[u]+1)continue;
depth[j+1]=depth[u]+1;
q.push(j+1);
}
}
}
if(depth[n+1]<=b)return 1;
return 0;
}
int main()
{
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>y[i];
}
if(a==1)
{
ll mask=(1ll<<60)-1;
for(ll i=59;i>=0;i--)
{
if(try1(mask-(1ll<<i)))
{
mask-=(1ll<<i);
}
}
cout<<mask<<endl;
}
ll mask=(1ll<<60)-1;
for(ll i=59;i>=0;i--)
{
if(try(mask-(1ll<<i)))
{
mask-=(1ll<<i);
}
}
cout<<mask<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
4608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
4460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
4460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |