이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=2005;
long long v[nmax];
int best[nmax];
bool dp[105][105];
long long sum,frb,ans;
int n,i,j,k,a,b;
bool chk_brt(long long val)
{
dp[0][0]=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
dp[i][j]=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
sum=0;
for(k=j;k>=1;k--)
{
sum+=v[k];
if((sum&frb)==0)
dp[i][j]|=dp[i-1][k-1];
}
if(i>=a&&i<=b&&dp[i][n])
return 1;
}
return 0;
}
bool chk_smen()
{
best[0]=0;
for(i=1;i<=n;i++)
best[i]=n+1;
for(i=1;i<=n;i++)
{
sum=0;
for(j=i;j>=1;j--)
{
sum+=v[j];
if((sum&frb)==0)
best[i]=min(best[i],best[j-1]+1);
}
}
return (best[n]<=b);
}
bool check(long long val)
{
frb=(((1LL<<61)-1)^val);
if(n<=100) return chk_brt(val);
return chk_smen();
}
int main()
{
//freopen("data.in","r",stdin);
cin>>n>>a>>b;
for(i=1;i<=n;i++)
cin>>v[i];
ans=(1LL<<61)-1;
for(long long p=60;p>=0;p--)
if(check(ans-(1LL<<p)))
ans-=(1LL<<p);
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |