#include <bits/stdc++.h>
using namespace std;
#define N 2010
#define ll long long
#define fs first
#define sc second
#define ii pair<ll,int>
#define pb push_back
#define int ll
int n,A,B,a[N],ans,dp[N][N];
void solve(int id)
{
int L=ans,R=ans+((1ll<<id)-1);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
if(a[i]>=L&&a[i]<=R)
dp[i][1]=1;
dp[i][1]+=dp[i-1][1];
}
for(int j=2;j<=B;j++)
{
int u=1,v=1;
for(int i=j;i<=n;i++)
{
while(u<i&&a[i]-a[u]>R)
u++;
while(v<i&&a[i]-a[v+1]>=L)
v++;
if(u<=v&&a[i]-a[u]<=R&&a[i]-a[v]>=L)
dp[i][j]=(dp[v][j-1]-dp[u-1][j-1]>0);
dp[i][j]+=dp[i-1][j];
}
}
for(int i=A;i<=B;i++)
if(dp[n][i]>dp[n-1][i])
return;
ans+=(1ll<<id);
}
int32_t main()
{
#ifdef SKY
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
#endif // SKY
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>A>>B;
for(int i=1;i<=n;i++)
cin>>a[i],a[i]+=a[i-1];
for(int i=40;i>=0;i--)
solve(i);
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
31952 KB |
Output is correct |
2 |
Incorrect |
139 ms |
31940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
31944 KB |
Output is correct |
2 |
Incorrect |
133 ms |
31932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
31828 KB |
Output is correct |
2 |
Incorrect |
142 ms |
31928 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
31940 KB |
Output is correct |
2 |
Incorrect |
142 ms |
31932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
31812 KB |
Output is correct |
2 |
Incorrect |
140 ms |
31932 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |