이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=100+5;
int n,a,b;
ll p[N];
ll ask(int st,int dr)
{
return p[dr]-p[st-1];
}
bool valid[N][N];
ll dp[N][N];
void b100()
{
for(int i=1;i<=n;i++)
{
valid[i][1]=1;
dp[i][1]=ask(1,i);
for(int j=2;j<=i;j++)
{
for(int ant=1;ant<i;ant++)
{
if(valid[ant][j-1])
{
ll val=(dp[ant][j-1]|ask(ant+1,i));
if(valid[i][j]==0)
{
valid[i][j]=1;
dp[i][j]=val;
}
else
{
dp[i][j]=min(dp[i][j],val);
}
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>a>>b;
for(int i=1;i<=n;i++)
{
ll x;
cin>>x;
p[i]=p[i-1]+x;
}
if(n<=100)
{
b100();
ll ans;
bool g=0;
for(int j=a;j<=b;j++)
{
if(valid[n][j]==0) continue;
if(g==0)
{
g=1;
ans=dp[n][j];
}
else
{
ans=min(ans,dp[n][j]);
}
}
cout<<ans<<"\n";
}
return 0;
}
/**
6 1 3
8 1 2 1 5 4
**/
# | 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... |