#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
//#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e3+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
vector<vector<int>> sums(MAXN,vector<int>(MAXN));
int n,a,b;
int pref[MAXN];
void checka1(int& ans, int bt)
{
vector<int> dp(MAXN, inf);
dp[0] = 0;
for(int i=1; i<=n; i++)
{
for(int j=i; j>0; j--)
{
int trsum = pref[i]- pref[j-1];
int p = trsum|ans;
if(p == ans)dp[i] = min(dp[i],dp[j-1] + 1);
}
//cout << dp[i] << endl;
}
if(dp[n] > b)ans|=(1ll<<bt);
}
void checkanije1(int& ans, int bt)
{
vector<vector<bool>> dp(MAXN, vector<bool>(MAXN, 0));
dp[0][0] = 1;
for(int i=1; i<=n; i++)
{
for(int j = 1; j<=i; j++)
{
for(int k=j; k<=i; k++)
{
int trsum = pref[i] - pref[k-1];
int p = trsum|ans;
if(p!=ans)continue;
dp[i][j] = (dp[i][j]| dp[k-1][j-1]);
}
}
}
for(int i=a; i<=b; i++)if(dp[n][i])return;
ans|= (1ll<<bt);
}
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
cin >> n >> a >> b;
vector<int>niz(n);
for(int i=0; i<n; i++)
{
cin >> niz[i];
pref[i+1] = pref[i] + niz[i];
}
for(int i=0; i<n; i++)for(int j=i; j<n; j++)sums[i][j] = pref[i+1]-pref[j];
if(a == 1)
{
int mxbit = 50;
int rez = (1ll<<(mxbit+1))-1;
for(int i=mxbit; i>=0; i--)
{
rez ^= (1ll<<i);
checka1(rez, i);
}
cout << rez << endl;
}
else
{
int mxbit = 50;
int rez = (1ll<<(mxbit+1))-1;
for(int i=mxbit; i>=0; i--)
{
rez ^= (1ll<<i);
checkanije1(rez, i);
}
cout << rez << endl;
}
}
}
/*
6 2 3
8 1 2 1 5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31832 KB |
Output is correct |
2 |
Correct |
14 ms |
31860 KB |
Output is correct |
3 |
Correct |
17 ms |
31996 KB |
Output is correct |
4 |
Correct |
14 ms |
31836 KB |
Output is correct |
5 |
Correct |
17 ms |
31864 KB |
Output is correct |
6 |
Correct |
13 ms |
31832 KB |
Output is correct |
7 |
Correct |
17 ms |
31832 KB |
Output is correct |
8 |
Correct |
17 ms |
31836 KB |
Output is correct |
9 |
Correct |
14 ms |
31836 KB |
Output is correct |
10 |
Correct |
13 ms |
31832 KB |
Output is correct |
11 |
Correct |
13 ms |
31884 KB |
Output is correct |
12 |
Correct |
16 ms |
31888 KB |
Output is correct |
13 |
Correct |
17 ms |
32128 KB |
Output is correct |
14 |
Correct |
30 ms |
32748 KB |
Output is correct |
15 |
Correct |
30 ms |
32600 KB |
Output is correct |
16 |
Correct |
30 ms |
32604 KB |
Output is correct |
17 |
Correct |
34 ms |
32592 KB |
Output is correct |
18 |
Correct |
28 ms |
32752 KB |
Output is correct |
19 |
Correct |
30 ms |
32600 KB |
Output is correct |
20 |
Correct |
30 ms |
32600 KB |
Output is correct |
21 |
Correct |
39 ms |
32600 KB |
Output is correct |
22 |
Correct |
31 ms |
32604 KB |
Output is correct |
23 |
Correct |
33 ms |
32604 KB |
Output is correct |
24 |
Correct |
40 ms |
32604 KB |
Output is correct |
25 |
Correct |
42 ms |
32592 KB |
Output is correct |
26 |
Correct |
35 ms |
32600 KB |
Output is correct |
27 |
Correct |
14 ms |
31836 KB |
Output is correct |
28 |
Correct |
15 ms |
31836 KB |
Output is correct |
29 |
Correct |
19 ms |
32088 KB |
Output is correct |
30 |
Correct |
14 ms |
31832 KB |
Output is correct |
31 |
Correct |
21 ms |
31836 KB |
Output is correct |
32 |
Correct |
21 ms |
31836 KB |
Output is correct |
33 |
Correct |
19 ms |
31836 KB |
Output is correct |
34 |
Correct |
15 ms |
31828 KB |
Output is correct |
35 |
Correct |
14 ms |
31836 KB |
Output is correct |
36 |
Correct |
13 ms |
31840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
32088 KB |
Output is correct |
2 |
Correct |
17 ms |
31836 KB |
Output is correct |
3 |
Correct |
15 ms |
31836 KB |
Output is correct |
4 |
Correct |
16 ms |
31836 KB |
Output is correct |
5 |
Correct |
13 ms |
31936 KB |
Output is correct |
6 |
Correct |
16 ms |
31928 KB |
Output is correct |
7 |
Correct |
22 ms |
31836 KB |
Output is correct |
8 |
Correct |
15 ms |
31836 KB |
Output is correct |
9 |
Correct |
14 ms |
31836 KB |
Output is correct |
10 |
Correct |
16 ms |
31836 KB |
Output is correct |
11 |
Correct |
15 ms |
31872 KB |
Output is correct |
12 |
Correct |
16 ms |
31836 KB |
Output is correct |
13 |
Correct |
14 ms |
31844 KB |
Output is correct |
14 |
Correct |
31 ms |
32600 KB |
Output is correct |
15 |
Correct |
31 ms |
32596 KB |
Output is correct |
16 |
Correct |
35 ms |
32604 KB |
Output is correct |
17 |
Correct |
30 ms |
32604 KB |
Output is correct |
18 |
Correct |
29 ms |
32600 KB |
Output is correct |
19 |
Correct |
29 ms |
32604 KB |
Output is correct |
20 |
Correct |
29 ms |
32600 KB |
Output is correct |
21 |
Correct |
32 ms |
32752 KB |
Output is correct |
22 |
Correct |
30 ms |
32604 KB |
Output is correct |
23 |
Correct |
31 ms |
32752 KB |
Output is correct |
24 |
Correct |
32 ms |
32796 KB |
Output is correct |
25 |
Correct |
32 ms |
32604 KB |
Output is correct |
26 |
Correct |
31 ms |
32600 KB |
Output is correct |
27 |
Correct |
16 ms |
31836 KB |
Output is correct |
28 |
Correct |
16 ms |
31836 KB |
Output is correct |
29 |
Correct |
14 ms |
31832 KB |
Output is correct |
30 |
Correct |
20 ms |
31828 KB |
Output is correct |
31 |
Correct |
16 ms |
31832 KB |
Output is correct |
32 |
Correct |
14 ms |
32016 KB |
Output is correct |
33 |
Correct |
15 ms |
31832 KB |
Output is correct |
34 |
Correct |
15 ms |
31832 KB |
Output is correct |
35 |
Correct |
15 ms |
31844 KB |
Output is correct |
36 |
Correct |
16 ms |
31832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31832 KB |
Output is correct |
2 |
Correct |
15 ms |
31832 KB |
Output is correct |
3 |
Correct |
16 ms |
31832 KB |
Output is correct |
4 |
Correct |
16 ms |
31836 KB |
Output is correct |
5 |
Correct |
15 ms |
31836 KB |
Output is correct |
6 |
Correct |
15 ms |
31788 KB |
Output is correct |
7 |
Correct |
15 ms |
31984 KB |
Output is correct |
8 |
Correct |
16 ms |
31836 KB |
Output is correct |
9 |
Correct |
15 ms |
31948 KB |
Output is correct |
10 |
Correct |
15 ms |
31944 KB |
Output is correct |
11 |
Correct |
15 ms |
31832 KB |
Output is correct |
12 |
Correct |
16 ms |
31836 KB |
Output is correct |
13 |
Correct |
15 ms |
31940 KB |
Output is correct |
14 |
Correct |
16 ms |
31920 KB |
Output is correct |
15 |
Correct |
15 ms |
32004 KB |
Output is correct |
16 |
Correct |
14 ms |
31836 KB |
Output is correct |
17 |
Correct |
14 ms |
31816 KB |
Output is correct |
18 |
Correct |
16 ms |
31832 KB |
Output is correct |
19 |
Correct |
15 ms |
32084 KB |
Output is correct |
20 |
Correct |
15 ms |
32004 KB |
Output is correct |
21 |
Correct |
15 ms |
31832 KB |
Output is correct |
22 |
Correct |
15 ms |
31832 KB |
Output is correct |
23 |
Correct |
15 ms |
31836 KB |
Output is correct |
24 |
Correct |
15 ms |
31836 KB |
Output is correct |
25 |
Correct |
15 ms |
31832 KB |
Output is correct |
26 |
Correct |
14 ms |
31836 KB |
Output is correct |
27 |
Correct |
14 ms |
31880 KB |
Output is correct |
28 |
Correct |
16 ms |
31832 KB |
Output is correct |
29 |
Correct |
14 ms |
31836 KB |
Output is correct |
30 |
Correct |
16 ms |
31956 KB |
Output is correct |
31 |
Correct |
17 ms |
31864 KB |
Output is correct |
32 |
Correct |
20 ms |
31836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
31836 KB |
Output is correct |
2 |
Correct |
15 ms |
31896 KB |
Output is correct |
3 |
Correct |
16 ms |
31836 KB |
Output is correct |
4 |
Correct |
14 ms |
31964 KB |
Output is correct |
5 |
Correct |
19 ms |
31836 KB |
Output is correct |
6 |
Correct |
15 ms |
31832 KB |
Output is correct |
7 |
Correct |
16 ms |
31836 KB |
Output is correct |
8 |
Correct |
14 ms |
31836 KB |
Output is correct |
9 |
Correct |
13 ms |
31864 KB |
Output is correct |
10 |
Correct |
15 ms |
31916 KB |
Output is correct |
11 |
Correct |
16 ms |
31836 KB |
Output is correct |
12 |
Correct |
16 ms |
31992 KB |
Output is correct |
13 |
Correct |
14 ms |
31836 KB |
Output is correct |
14 |
Correct |
29 ms |
32588 KB |
Output is correct |
15 |
Correct |
31 ms |
32604 KB |
Output is correct |
16 |
Correct |
31 ms |
32580 KB |
Output is correct |
17 |
Correct |
34 ms |
32604 KB |
Output is correct |
18 |
Correct |
31 ms |
32760 KB |
Output is correct |
19 |
Correct |
31 ms |
32604 KB |
Output is correct |
20 |
Correct |
31 ms |
32604 KB |
Output is correct |
21 |
Correct |
30 ms |
32600 KB |
Output is correct |
22 |
Correct |
35 ms |
32604 KB |
Output is correct |
23 |
Correct |
30 ms |
32604 KB |
Output is correct |
24 |
Correct |
29 ms |
32604 KB |
Output is correct |
25 |
Correct |
30 ms |
32600 KB |
Output is correct |
26 |
Correct |
32 ms |
32600 KB |
Output is correct |
27 |
Correct |
16 ms |
31956 KB |
Output is correct |
28 |
Correct |
14 ms |
31836 KB |
Output is correct |
29 |
Correct |
15 ms |
31944 KB |
Output is correct |
30 |
Correct |
14 ms |
31892 KB |
Output is correct |
31 |
Correct |
14 ms |
31832 KB |
Output is correct |
32 |
Correct |
17 ms |
31832 KB |
Output is correct |
33 |
Correct |
16 ms |
31904 KB |
Output is correct |
34 |
Correct |
14 ms |
31836 KB |
Output is correct |
35 |
Correct |
13 ms |
31836 KB |
Output is correct |
36 |
Correct |
15 ms |
31836 KB |
Output is correct |
37 |
Correct |
19 ms |
31848 KB |
Output is correct |
38 |
Correct |
16 ms |
31832 KB |
Output is correct |
39 |
Correct |
16 ms |
31836 KB |
Output is correct |
40 |
Correct |
15 ms |
31836 KB |
Output is correct |
41 |
Correct |
15 ms |
31912 KB |
Output is correct |
42 |
Correct |
15 ms |
31836 KB |
Output is correct |
43 |
Correct |
14 ms |
32020 KB |
Output is correct |
44 |
Correct |
14 ms |
31848 KB |
Output is correct |
45 |
Correct |
15 ms |
31940 KB |
Output is correct |
46 |
Correct |
17 ms |
31836 KB |
Output is correct |
47 |
Correct |
14 ms |
31836 KB |
Output is correct |
48 |
Correct |
15 ms |
31944 KB |
Output is correct |
49 |
Correct |
16 ms |
31816 KB |
Output is correct |
50 |
Correct |
16 ms |
31836 KB |
Output is correct |
51 |
Correct |
16 ms |
31832 KB |
Output is correct |
52 |
Correct |
16 ms |
31836 KB |
Output is correct |
53 |
Correct |
15 ms |
31836 KB |
Output is correct |
54 |
Correct |
15 ms |
31988 KB |
Output is correct |
55 |
Correct |
15 ms |
32012 KB |
Output is correct |
56 |
Correct |
15 ms |
31836 KB |
Output is correct |
57 |
Correct |
16 ms |
31832 KB |
Output is correct |
58 |
Correct |
15 ms |
31804 KB |
Output is correct |
59 |
Correct |
14 ms |
31832 KB |
Output is correct |
60 |
Correct |
17 ms |
31832 KB |
Output is correct |
61 |
Correct |
15 ms |
31920 KB |
Output is correct |
62 |
Correct |
15 ms |
31836 KB |
Output is correct |
63 |
Correct |
15 ms |
31996 KB |
Output is correct |
64 |
Correct |
48 ms |
32596 KB |
Output is correct |
65 |
Correct |
34 ms |
32752 KB |
Output is correct |
66 |
Correct |
34 ms |
32600 KB |
Output is correct |
67 |
Correct |
39 ms |
32600 KB |
Output is correct |
68 |
Correct |
44 ms |
32592 KB |
Output is correct |
69 |
Correct |
50 ms |
32576 KB |
Output is correct |
70 |
Correct |
48 ms |
32600 KB |
Output is correct |
71 |
Correct |
49 ms |
32600 KB |
Output is correct |
72 |
Correct |
49 ms |
32604 KB |
Output is correct |
73 |
Correct |
50 ms |
32748 KB |
Output is correct |
74 |
Correct |
49 ms |
32600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31812 KB |
Output is correct |
2 |
Correct |
15 ms |
31836 KB |
Output is correct |
3 |
Correct |
16 ms |
31836 KB |
Output is correct |
4 |
Correct |
16 ms |
31836 KB |
Output is correct |
5 |
Correct |
17 ms |
31832 KB |
Output is correct |
6 |
Correct |
16 ms |
31836 KB |
Output is correct |
7 |
Correct |
16 ms |
31836 KB |
Output is correct |
8 |
Correct |
16 ms |
31876 KB |
Output is correct |
9 |
Correct |
16 ms |
31836 KB |
Output is correct |
10 |
Correct |
16 ms |
31836 KB |
Output is correct |
11 |
Correct |
15 ms |
31836 KB |
Output is correct |
12 |
Correct |
15 ms |
31936 KB |
Output is correct |
13 |
Correct |
14 ms |
31836 KB |
Output is correct |
14 |
Correct |
16 ms |
31832 KB |
Output is correct |
15 |
Correct |
14 ms |
31956 KB |
Output is correct |
16 |
Correct |
15 ms |
31836 KB |
Output is correct |
17 |
Correct |
15 ms |
31880 KB |
Output is correct |
18 |
Correct |
15 ms |
31808 KB |
Output is correct |
19 |
Correct |
14 ms |
31908 KB |
Output is correct |
20 |
Correct |
16 ms |
31836 KB |
Output is correct |
21 |
Correct |
17 ms |
31888 KB |
Output is correct |
22 |
Correct |
15 ms |
31836 KB |
Output is correct |
23 |
Correct |
15 ms |
31836 KB |
Output is correct |
24 |
Correct |
14 ms |
31788 KB |
Output is correct |
25 |
Correct |
16 ms |
31880 KB |
Output is correct |
26 |
Correct |
14 ms |
31836 KB |
Output is correct |
27 |
Correct |
14 ms |
31836 KB |
Output is correct |
28 |
Correct |
15 ms |
31896 KB |
Output is correct |
29 |
Correct |
15 ms |
31956 KB |
Output is correct |
30 |
Correct |
14 ms |
31832 KB |
Output is correct |
31 |
Correct |
19 ms |
31832 KB |
Output is correct |
32 |
Correct |
14 ms |
31880 KB |
Output is correct |
33 |
Correct |
14 ms |
31832 KB |
Output is correct |
34 |
Correct |
15 ms |
31832 KB |
Output is correct |
35 |
Correct |
16 ms |
31836 KB |
Output is correct |
36 |
Correct |
15 ms |
31904 KB |
Output is correct |
37 |
Correct |
16 ms |
32016 KB |
Output is correct |
38 |
Correct |
16 ms |
31836 KB |
Output is correct |
39 |
Correct |
14 ms |
31832 KB |
Output is correct |
40 |
Correct |
17 ms |
31836 KB |
Output is correct |
41 |
Correct |
14 ms |
31832 KB |
Output is correct |
42 |
Correct |
15 ms |
31836 KB |
Output is correct |
43 |
Correct |
14 ms |
31832 KB |
Output is correct |
44 |
Correct |
16 ms |
31832 KB |
Output is correct |
45 |
Correct |
16 ms |
31836 KB |
Output is correct |
46 |
Correct |
14 ms |
31832 KB |
Output is correct |
47 |
Correct |
14 ms |
31836 KB |
Output is correct |
48 |
Correct |
17 ms |
31836 KB |
Output is correct |
49 |
Correct |
14 ms |
31836 KB |
Output is correct |
50 |
Correct |
16 ms |
31828 KB |
Output is correct |
51 |
Correct |
16 ms |
31832 KB |
Output is correct |
52 |
Correct |
23 ms |
31836 KB |
Output is correct |
53 |
Correct |
28 ms |
31832 KB |
Output is correct |
54 |
Correct |
41 ms |
31836 KB |
Output is correct |
55 |
Correct |
40 ms |
31832 KB |
Output is correct |
56 |
Correct |
116 ms |
31836 KB |
Output is correct |
57 |
Correct |
115 ms |
31912 KB |
Output is correct |
58 |
Correct |
115 ms |
31836 KB |
Output is correct |
59 |
Correct |
115 ms |
31836 KB |
Output is correct |
60 |
Correct |
117 ms |
32044 KB |
Output is correct |
61 |
Correct |
16 ms |
31832 KB |
Output is correct |
62 |
Correct |
29 ms |
31920 KB |
Output is correct |
63 |
Correct |
45 ms |
31832 KB |
Output is correct |
64 |
Correct |
41 ms |
31832 KB |
Output is correct |
65 |
Correct |
66 ms |
31832 KB |
Output is correct |
66 |
Correct |
95 ms |
32060 KB |
Output is correct |
67 |
Correct |
115 ms |
31836 KB |
Output is correct |
68 |
Correct |
125 ms |
31836 KB |
Output is correct |
69 |
Correct |
115 ms |
31832 KB |
Output is correct |