#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=2001;
const int mod=998244353;
const int mxlogN=40;
const int mxK=26;
const ll inf=1e18;
const int K=600;
int dp[mxN][mxN], a[mxN];
ll check(int i, int k, ll msk, int n)
{
if(i==n) return k==0;
if(!k) return 0;
if(~dp[i][k]) return dp[i][k];
ll sum=0;
for(int j=i+1; j<=n; j++)
{
sum+=a[j-1];
if((msk&sum)==sum) if(check(j,k-1,msk,n)) return dp[i][k]=1;
}
return dp[i][k]=0;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
int n,A,B; cin >> n >> A >> B;
for(int i=0; i<n; i++) cin >> a[i];
ll ans=inf;
for(int k=A; k<=B; k++)
{
ll msk=(1LL<<(mxlogN+1))-1;
for(int j=0; j<=mxlogN; j++)
{
msk^=check(0,k,msk^1LL<<(mxlogN-j),n)<<(mxlogN-j);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
}
ans=min(ans,msk);
}
cout << ans << "\n";
}
/*
6 2 2
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
15984 KB |
Output is correct |
2 |
Correct |
280 ms |
15980 KB |
Output is correct |
3 |
Correct |
81 ms |
15956 KB |
Output is correct |
4 |
Correct |
206 ms |
15980 KB |
Output is correct |
5 |
Correct |
75 ms |
15980 KB |
Output is correct |
6 |
Execution timed out |
1008 ms |
15984 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
15992 KB |
Output is correct |
2 |
Correct |
305 ms |
15996 KB |
Output is correct |
3 |
Correct |
78 ms |
15984 KB |
Output is correct |
4 |
Correct |
223 ms |
15956 KB |
Output is correct |
5 |
Correct |
75 ms |
15984 KB |
Output is correct |
6 |
Execution timed out |
1032 ms |
15956 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
15956 KB |
Output is correct |
2 |
Correct |
276 ms |
15988 KB |
Output is correct |
3 |
Correct |
74 ms |
15956 KB |
Output is correct |
4 |
Correct |
211 ms |
15984 KB |
Output is correct |
5 |
Correct |
73 ms |
15984 KB |
Output is correct |
6 |
Execution timed out |
1044 ms |
15984 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
15956 KB |
Output is correct |
2 |
Correct |
298 ms |
15980 KB |
Output is correct |
3 |
Correct |
74 ms |
15984 KB |
Output is correct |
4 |
Correct |
207 ms |
15992 KB |
Output is correct |
5 |
Correct |
83 ms |
15988 KB |
Output is correct |
6 |
Execution timed out |
1041 ms |
15984 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
15980 KB |
Output is correct |
2 |
Correct |
277 ms |
15980 KB |
Output is correct |
3 |
Correct |
84 ms |
15956 KB |
Output is correct |
4 |
Correct |
231 ms |
15956 KB |
Output is correct |
5 |
Correct |
76 ms |
15996 KB |
Output is correct |
6 |
Execution timed out |
1039 ms |
15984 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |