#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
typedef long long ll;
using namespace std;
// 1-indexovanie!!!
const int maxn = 2005;
const ll logn = 41;
int n, a, b;
vector<ll> pf(maxn);
vector<vector<ll> > dp(maxn, vector<ll>(maxn, 0));
ll f(int l, int r) { return pf[r] - pf[l - 1]; }
bool check(ll mask) // existuje platne riesenie ak or tych suctov sa musi zmestit do tejto masky
{
if (a == 1)
{
vector<int> d(n+1, maxn);
queue<int> q;
q.push(0), d[0] = 0;
while (!q.empty())
{
int i = q.front();
q.pop();
for (int j = i+1; j <= n; j++) if (d[j] == maxn && ((f(i+1, j)|mask) == mask))
d[j] = d[i] + 1, q.push(j);
}
return d[n] <= b;
}
for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 0;
dp[0][0] = 1;
for (int i = 0; i < n; i++) for (int cnt = 0; cnt <= i; cnt++) if (dp[i][cnt])
for (int j = i + 1; j <= n; j++) if ((f(i + 1, j) | mask) == mask)
dp[j][cnt + 1] = 1;
for (int cnt = a; cnt <= b; cnt++) if (dp[n][cnt]) return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> pf[i], pf[i] += pf[i - 1];
ll mask = (1ll << logn) - 1;
for (ll i = logn - 1; i >= 0; i--)
{
if (check(mask - (1ll << i))) mask -= (1ll << i);
}
cout << mask << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31752 KB |
Output is correct |
2 |
Correct |
16 ms |
31848 KB |
Output is correct |
3 |
Correct |
16 ms |
31820 KB |
Output is correct |
4 |
Correct |
16 ms |
31948 KB |
Output is correct |
5 |
Correct |
19 ms |
31820 KB |
Output is correct |
6 |
Correct |
18 ms |
31868 KB |
Output is correct |
7 |
Correct |
16 ms |
31756 KB |
Output is correct |
8 |
Correct |
17 ms |
31856 KB |
Output is correct |
9 |
Correct |
18 ms |
31820 KB |
Output is correct |
10 |
Correct |
16 ms |
31804 KB |
Output is correct |
11 |
Correct |
16 ms |
31868 KB |
Output is correct |
12 |
Correct |
16 ms |
31820 KB |
Output is correct |
13 |
Correct |
16 ms |
31820 KB |
Output is correct |
14 |
Correct |
15 ms |
31856 KB |
Output is correct |
15 |
Correct |
15 ms |
31820 KB |
Output is correct |
16 |
Correct |
15 ms |
31820 KB |
Output is correct |
17 |
Correct |
15 ms |
31808 KB |
Output is correct |
18 |
Correct |
15 ms |
31864 KB |
Output is correct |
19 |
Correct |
15 ms |
31820 KB |
Output is correct |
20 |
Correct |
18 ms |
31856 KB |
Output is correct |
21 |
Correct |
21 ms |
31796 KB |
Output is correct |
22 |
Correct |
17 ms |
31820 KB |
Output is correct |
23 |
Correct |
15 ms |
31872 KB |
Output is correct |
24 |
Correct |
15 ms |
31872 KB |
Output is correct |
25 |
Correct |
15 ms |
31876 KB |
Output is correct |
26 |
Correct |
16 ms |
31868 KB |
Output is correct |
27 |
Correct |
15 ms |
31820 KB |
Output is correct |
28 |
Correct |
29 ms |
31816 KB |
Output is correct |
29 |
Correct |
15 ms |
31856 KB |
Output is correct |
30 |
Correct |
15 ms |
31820 KB |
Output is correct |
31 |
Correct |
16 ms |
31820 KB |
Output is correct |
32 |
Correct |
15 ms |
31760 KB |
Output is correct |
33 |
Correct |
20 ms |
31724 KB |
Output is correct |
34 |
Correct |
18 ms |
31820 KB |
Output is correct |
35 |
Correct |
17 ms |
31872 KB |
Output is correct |
36 |
Correct |
16 ms |
31816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31812 KB |
Output is correct |
2 |
Correct |
16 ms |
31868 KB |
Output is correct |
3 |
Correct |
20 ms |
31820 KB |
Output is correct |
4 |
Correct |
19 ms |
31872 KB |
Output is correct |
5 |
Correct |
16 ms |
31872 KB |
Output is correct |
6 |
Correct |
16 ms |
31808 KB |
Output is correct |
7 |
Correct |
17 ms |
31820 KB |
Output is correct |
8 |
Correct |
16 ms |
31764 KB |
Output is correct |
9 |
Correct |
16 ms |
31796 KB |
Output is correct |
10 |
Correct |
17 ms |
31772 KB |
Output is correct |
11 |
Correct |
17 ms |
31876 KB |
Output is correct |
12 |
Correct |
16 ms |
31760 KB |
Output is correct |
13 |
Correct |
16 ms |
31864 KB |
Output is correct |
14 |
Correct |
20 ms |
31824 KB |
Output is correct |
15 |
Correct |
18 ms |
31864 KB |
Output is correct |
16 |
Correct |
17 ms |
31808 KB |
Output is correct |
17 |
Correct |
17 ms |
31848 KB |
Output is correct |
18 |
Correct |
16 ms |
31864 KB |
Output is correct |
19 |
Correct |
20 ms |
31780 KB |
Output is correct |
20 |
Correct |
18 ms |
31868 KB |
Output is correct |
21 |
Correct |
17 ms |
31872 KB |
Output is correct |
22 |
Correct |
20 ms |
31820 KB |
Output is correct |
23 |
Correct |
17 ms |
31828 KB |
Output is correct |
24 |
Correct |
20 ms |
31768 KB |
Output is correct |
25 |
Correct |
17 ms |
31844 KB |
Output is correct |
26 |
Correct |
20 ms |
31836 KB |
Output is correct |
27 |
Correct |
16 ms |
31844 KB |
Output is correct |
28 |
Correct |
16 ms |
31872 KB |
Output is correct |
29 |
Correct |
18 ms |
31868 KB |
Output is correct |
30 |
Correct |
17 ms |
31860 KB |
Output is correct |
31 |
Correct |
16 ms |
31784 KB |
Output is correct |
32 |
Correct |
16 ms |
31828 KB |
Output is correct |
33 |
Correct |
18 ms |
31868 KB |
Output is correct |
34 |
Correct |
17 ms |
31848 KB |
Output is correct |
35 |
Correct |
19 ms |
31948 KB |
Output is correct |
36 |
Correct |
19 ms |
31848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31852 KB |
Output is correct |
2 |
Correct |
16 ms |
31784 KB |
Output is correct |
3 |
Correct |
17 ms |
31872 KB |
Output is correct |
4 |
Correct |
16 ms |
31808 KB |
Output is correct |
5 |
Correct |
17 ms |
31820 KB |
Output is correct |
6 |
Correct |
16 ms |
31820 KB |
Output is correct |
7 |
Correct |
16 ms |
31820 KB |
Output is correct |
8 |
Correct |
17 ms |
31864 KB |
Output is correct |
9 |
Correct |
16 ms |
31788 KB |
Output is correct |
10 |
Correct |
17 ms |
31796 KB |
Output is correct |
11 |
Correct |
16 ms |
31812 KB |
Output is correct |
12 |
Correct |
17 ms |
31820 KB |
Output is correct |
13 |
Correct |
17 ms |
31784 KB |
Output is correct |
14 |
Correct |
16 ms |
31756 KB |
Output is correct |
15 |
Correct |
18 ms |
31948 KB |
Output is correct |
16 |
Correct |
16 ms |
31820 KB |
Output is correct |
17 |
Correct |
16 ms |
31832 KB |
Output is correct |
18 |
Correct |
16 ms |
31876 KB |
Output is correct |
19 |
Correct |
18 ms |
31804 KB |
Output is correct |
20 |
Correct |
17 ms |
31820 KB |
Output is correct |
21 |
Correct |
17 ms |
31792 KB |
Output is correct |
22 |
Correct |
20 ms |
31856 KB |
Output is correct |
23 |
Correct |
18 ms |
31756 KB |
Output is correct |
24 |
Correct |
16 ms |
31872 KB |
Output is correct |
25 |
Correct |
17 ms |
31848 KB |
Output is correct |
26 |
Correct |
17 ms |
31872 KB |
Output is correct |
27 |
Correct |
19 ms |
31772 KB |
Output is correct |
28 |
Correct |
19 ms |
31816 KB |
Output is correct |
29 |
Correct |
17 ms |
31800 KB |
Output is correct |
30 |
Correct |
18 ms |
31820 KB |
Output is correct |
31 |
Correct |
16 ms |
31852 KB |
Output is correct |
32 |
Correct |
17 ms |
31808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
31860 KB |
Output is correct |
2 |
Correct |
17 ms |
31876 KB |
Output is correct |
3 |
Correct |
16 ms |
31820 KB |
Output is correct |
4 |
Correct |
16 ms |
31824 KB |
Output is correct |
5 |
Correct |
16 ms |
31820 KB |
Output is correct |
6 |
Correct |
20 ms |
31800 KB |
Output is correct |
7 |
Correct |
16 ms |
31820 KB |
Output is correct |
8 |
Correct |
16 ms |
31876 KB |
Output is correct |
9 |
Correct |
16 ms |
31820 KB |
Output is correct |
10 |
Correct |
17 ms |
31820 KB |
Output is correct |
11 |
Correct |
17 ms |
31876 KB |
Output is correct |
12 |
Correct |
16 ms |
31820 KB |
Output is correct |
13 |
Correct |
18 ms |
31800 KB |
Output is correct |
14 |
Correct |
18 ms |
31820 KB |
Output is correct |
15 |
Correct |
16 ms |
31824 KB |
Output is correct |
16 |
Correct |
19 ms |
31820 KB |
Output is correct |
17 |
Correct |
16 ms |
31872 KB |
Output is correct |
18 |
Correct |
17 ms |
31772 KB |
Output is correct |
19 |
Correct |
17 ms |
31828 KB |
Output is correct |
20 |
Correct |
17 ms |
31780 KB |
Output is correct |
21 |
Correct |
16 ms |
31820 KB |
Output is correct |
22 |
Correct |
16 ms |
31808 KB |
Output is correct |
23 |
Correct |
16 ms |
31816 KB |
Output is correct |
24 |
Correct |
16 ms |
31868 KB |
Output is correct |
25 |
Correct |
18 ms |
31820 KB |
Output is correct |
26 |
Correct |
17 ms |
31820 KB |
Output is correct |
27 |
Correct |
16 ms |
31792 KB |
Output is correct |
28 |
Correct |
16 ms |
31820 KB |
Output is correct |
29 |
Correct |
18 ms |
31772 KB |
Output is correct |
30 |
Correct |
16 ms |
31820 KB |
Output is correct |
31 |
Correct |
16 ms |
31868 KB |
Output is correct |
32 |
Correct |
16 ms |
31828 KB |
Output is correct |
33 |
Correct |
16 ms |
31820 KB |
Output is correct |
34 |
Correct |
17 ms |
31816 KB |
Output is correct |
35 |
Correct |
16 ms |
31820 KB |
Output is correct |
36 |
Correct |
16 ms |
31872 KB |
Output is correct |
37 |
Correct |
16 ms |
31820 KB |
Output is correct |
38 |
Correct |
16 ms |
31772 KB |
Output is correct |
39 |
Correct |
16 ms |
31872 KB |
Output is correct |
40 |
Correct |
16 ms |
31752 KB |
Output is correct |
41 |
Correct |
17 ms |
31752 KB |
Output is correct |
42 |
Correct |
17 ms |
31820 KB |
Output is correct |
43 |
Correct |
18 ms |
31820 KB |
Output is correct |
44 |
Correct |
16 ms |
31840 KB |
Output is correct |
45 |
Correct |
16 ms |
31856 KB |
Output is correct |
46 |
Correct |
17 ms |
31828 KB |
Output is correct |
47 |
Correct |
17 ms |
31868 KB |
Output is correct |
48 |
Correct |
16 ms |
31820 KB |
Output is correct |
49 |
Correct |
17 ms |
31828 KB |
Output is correct |
50 |
Correct |
16 ms |
31764 KB |
Output is correct |
51 |
Correct |
15 ms |
31868 KB |
Output is correct |
52 |
Correct |
16 ms |
31820 KB |
Output is correct |
53 |
Correct |
17 ms |
31832 KB |
Output is correct |
54 |
Correct |
17 ms |
31800 KB |
Output is correct |
55 |
Correct |
18 ms |
31872 KB |
Output is correct |
56 |
Correct |
17 ms |
31820 KB |
Output is correct |
57 |
Correct |
17 ms |
31820 KB |
Output is correct |
58 |
Correct |
16 ms |
31876 KB |
Output is correct |
59 |
Correct |
16 ms |
31820 KB |
Output is correct |
60 |
Correct |
16 ms |
31864 KB |
Output is correct |
61 |
Correct |
17 ms |
31812 KB |
Output is correct |
62 |
Correct |
16 ms |
31840 KB |
Output is correct |
63 |
Correct |
17 ms |
31824 KB |
Output is correct |
64 |
Correct |
29 ms |
31820 KB |
Output is correct |
65 |
Correct |
17 ms |
31788 KB |
Output is correct |
66 |
Correct |
18 ms |
31784 KB |
Output is correct |
67 |
Correct |
19 ms |
31820 KB |
Output is correct |
68 |
Correct |
21 ms |
31820 KB |
Output is correct |
69 |
Correct |
22 ms |
31828 KB |
Output is correct |
70 |
Correct |
23 ms |
31848 KB |
Output is correct |
71 |
Correct |
21 ms |
31868 KB |
Output is correct |
72 |
Correct |
22 ms |
31820 KB |
Output is correct |
73 |
Correct |
23 ms |
31756 KB |
Output is correct |
74 |
Correct |
26 ms |
31868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31820 KB |
Output is correct |
2 |
Correct |
16 ms |
31764 KB |
Output is correct |
3 |
Correct |
15 ms |
31800 KB |
Output is correct |
4 |
Correct |
16 ms |
31864 KB |
Output is correct |
5 |
Correct |
17 ms |
31760 KB |
Output is correct |
6 |
Correct |
16 ms |
31796 KB |
Output is correct |
7 |
Correct |
17 ms |
31748 KB |
Output is correct |
8 |
Correct |
17 ms |
31820 KB |
Output is correct |
9 |
Correct |
16 ms |
31820 KB |
Output is correct |
10 |
Correct |
16 ms |
31820 KB |
Output is correct |
11 |
Correct |
16 ms |
31820 KB |
Output is correct |
12 |
Correct |
16 ms |
31848 KB |
Output is correct |
13 |
Correct |
18 ms |
31920 KB |
Output is correct |
14 |
Correct |
16 ms |
31800 KB |
Output is correct |
15 |
Correct |
17 ms |
31868 KB |
Output is correct |
16 |
Correct |
16 ms |
31776 KB |
Output is correct |
17 |
Correct |
16 ms |
31820 KB |
Output is correct |
18 |
Correct |
16 ms |
31820 KB |
Output is correct |
19 |
Correct |
16 ms |
31816 KB |
Output is correct |
20 |
Correct |
16 ms |
31756 KB |
Output is correct |
21 |
Correct |
16 ms |
31840 KB |
Output is correct |
22 |
Correct |
17 ms |
31820 KB |
Output is correct |
23 |
Correct |
17 ms |
31820 KB |
Output is correct |
24 |
Correct |
15 ms |
31820 KB |
Output is correct |
25 |
Correct |
16 ms |
31800 KB |
Output is correct |
26 |
Correct |
16 ms |
31820 KB |
Output is correct |
27 |
Correct |
16 ms |
31840 KB |
Output is correct |
28 |
Correct |
18 ms |
31856 KB |
Output is correct |
29 |
Correct |
16 ms |
31820 KB |
Output is correct |
30 |
Correct |
17 ms |
31872 KB |
Output is correct |
31 |
Correct |
18 ms |
31824 KB |
Output is correct |
32 |
Correct |
17 ms |
31820 KB |
Output is correct |
33 |
Correct |
17 ms |
31864 KB |
Output is correct |
34 |
Correct |
17 ms |
31832 KB |
Output is correct |
35 |
Correct |
16 ms |
31872 KB |
Output is correct |
36 |
Correct |
17 ms |
31860 KB |
Output is correct |
37 |
Correct |
17 ms |
31868 KB |
Output is correct |
38 |
Correct |
17 ms |
31820 KB |
Output is correct |
39 |
Correct |
18 ms |
32012 KB |
Output is correct |
40 |
Correct |
16 ms |
31800 KB |
Output is correct |
41 |
Correct |
16 ms |
31820 KB |
Output is correct |
42 |
Correct |
16 ms |
31820 KB |
Output is correct |
43 |
Correct |
15 ms |
31820 KB |
Output is correct |
44 |
Correct |
16 ms |
31824 KB |
Output is correct |
45 |
Correct |
17 ms |
31820 KB |
Output is correct |
46 |
Correct |
17 ms |
31820 KB |
Output is correct |
47 |
Correct |
17 ms |
31800 KB |
Output is correct |
48 |
Correct |
17 ms |
31764 KB |
Output is correct |
49 |
Correct |
17 ms |
31784 KB |
Output is correct |
50 |
Correct |
20 ms |
31808 KB |
Output is correct |
51 |
Correct |
17 ms |
31820 KB |
Output is correct |
52 |
Correct |
21 ms |
31796 KB |
Output is correct |
53 |
Correct |
21 ms |
31820 KB |
Output is correct |
54 |
Correct |
41 ms |
31800 KB |
Output is correct |
55 |
Correct |
33 ms |
31820 KB |
Output is correct |
56 |
Correct |
47 ms |
31996 KB |
Output is correct |
57 |
Correct |
41 ms |
31872 KB |
Output is correct |
58 |
Correct |
59 ms |
31876 KB |
Output is correct |
59 |
Correct |
81 ms |
31820 KB |
Output is correct |
60 |
Correct |
49 ms |
31872 KB |
Output is correct |
61 |
Correct |
17 ms |
31872 KB |
Output is correct |
62 |
Correct |
20 ms |
31872 KB |
Output is correct |
63 |
Correct |
41 ms |
31868 KB |
Output is correct |
64 |
Correct |
23 ms |
31788 KB |
Output is correct |
65 |
Correct |
28 ms |
31868 KB |
Output is correct |
66 |
Correct |
35 ms |
31868 KB |
Output is correct |
67 |
Correct |
38 ms |
31784 KB |
Output is correct |
68 |
Correct |
113 ms |
31872 KB |
Output is correct |
69 |
Correct |
49 ms |
31940 KB |
Output is correct |