#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 100 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;
ll n, a, b, Y[N], dp[N][505][N], pref[N], max_value, ans = INF, mxY = 0, dp2[N][2005];
int main(){
speed;
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
cin >> Y[i];
mxY = max(mxY, Y[i]);
pref[i] = pref[i - 1] + Y[i];
}
if(n <= 20){
for(ll col = a; col <= b; col++){
for(ll mask = 0; mask < (1 << (n - 1)); mask++){
if(__builtin_popcount(mask) != (col - 1))
continue;
// cout << "FOUND " << mask << endl;
ll last = 0, cur = 0;
for(int i = 0; i < n; i++){
if((1 << i) & mask){
cur = (cur | (pref[i + 1] - pref[last]));
last = i + 1;
}
}
cur = (cur | (pref[n] - pref[last]));
ans = min(ans, cur);
}
}
cout << ans << endl;
return 0;
}
if(n <= 50 && mxY <= 10){
max_value = 10 * n;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= max_value; j++){
for(int z = 0; z <= n; z++){
dp[i][j][z] = 0;
}
}
}
dp[0][0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = 0; j < i; j++){
for(int curor = 0; curor <= max_value; curor++){
for(int part = 0; part < n; part++){
ll sum = pref[i] - pref[j];
if(!dp[j][curor][part])
continue;
dp[i][(curor | sum)][part + 1] = 1;
}
}
}
}
for(ll curor = 0; curor <= max_value; curor++){
for(int part = a; part <= b; part++){
if(dp[n][curor][part] == 0)
continue;
ans = min(ans, curor);
}
}
cout << ans << endl;
return 0;
}
max_value = 20 * n;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= max_value; j++){
dp2[i][j] = INF;
}
}
dp2[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < i; j++){
ll sum = pref[i] - pref[j];
for(int curor = 0; curor <= max_value; curor++){
dp2[i][(curor | sum)] = min(dp2[i][(curor | sum)], dp2[j][curor] + 1ll);
}
}
}
for(ll curor = 0; curor <= max_value; curor++){
for(int part = a; part <= b; part++){
if(dp2[n][curor] < INF)
ans = min(ans, curor);
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
212 KB |
Output is correct |
13 |
Correct |
58 ms |
312 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
9 ms |
340 KB |
Output is correct |
22 |
Correct |
9 ms |
332 KB |
Output is correct |
23 |
Correct |
9 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
13 ms |
332 KB |
Output is correct |
26 |
Correct |
42 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
15 ms |
328 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
49 ms |
316 KB |
Output is correct |
34 |
Correct |
63 ms |
212 KB |
Output is correct |
35 |
Correct |
5 ms |
212 KB |
Output is correct |
36 |
Correct |
64 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
212 KB |
Output is correct |
10 |
Correct |
6 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
212 KB |
Output is correct |
13 |
Correct |
62 ms |
324 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
9 ms |
212 KB |
Output is correct |
22 |
Correct |
11 ms |
212 KB |
Output is correct |
23 |
Correct |
9 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
13 ms |
212 KB |
Output is correct |
26 |
Correct |
43 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
4180 KB |
Output is correct |
28 |
Correct |
6 ms |
5716 KB |
Output is correct |
29 |
Correct |
24 ms |
12628 KB |
Output is correct |
30 |
Correct |
37 ms |
15316 KB |
Output is correct |
31 |
Correct |
71 ms |
21476 KB |
Output is correct |
32 |
Correct |
66 ms |
21460 KB |
Output is correct |
33 |
Correct |
64 ms |
21460 KB |
Output is correct |
34 |
Correct |
64 ms |
21460 KB |
Output is correct |
35 |
Correct |
63 ms |
21484 KB |
Output is correct |
36 |
Correct |
69 ms |
21476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
212 KB |
Output is correct |
9 |
Correct |
6 ms |
212 KB |
Output is correct |
10 |
Correct |
6 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
58 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
7 ms |
5716 KB |
Output is correct |
16 |
Correct |
25 ms |
12564 KB |
Output is correct |
17 |
Correct |
39 ms |
15348 KB |
Output is correct |
18 |
Correct |
66 ms |
21460 KB |
Output is correct |
19 |
Correct |
65 ms |
21460 KB |
Output is correct |
20 |
Correct |
70 ms |
21480 KB |
Output is correct |
21 |
Correct |
70 ms |
21460 KB |
Output is correct |
22 |
Correct |
63 ms |
21476 KB |
Output is correct |
23 |
Correct |
63 ms |
21460 KB |
Output is correct |
24 |
Correct |
3 ms |
852 KB |
Output is correct |
25 |
Incorrect |
4 ms |
1236 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
328 KB |
Output is correct |
12 |
Correct |
5 ms |
212 KB |
Output is correct |
13 |
Correct |
59 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
9 ms |
212 KB |
Output is correct |
22 |
Correct |
9 ms |
328 KB |
Output is correct |
23 |
Correct |
9 ms |
212 KB |
Output is correct |
24 |
Correct |
2 ms |
212 KB |
Output is correct |
25 |
Correct |
13 ms |
332 KB |
Output is correct |
26 |
Correct |
47 ms |
324 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
14 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
53 ms |
212 KB |
Output is correct |
34 |
Correct |
64 ms |
308 KB |
Output is correct |
35 |
Correct |
5 ms |
212 KB |
Output is correct |
36 |
Correct |
63 ms |
308 KB |
Output is correct |
37 |
Correct |
3 ms |
4180 KB |
Output is correct |
38 |
Correct |
5 ms |
5716 KB |
Output is correct |
39 |
Correct |
25 ms |
12680 KB |
Output is correct |
40 |
Correct |
36 ms |
15308 KB |
Output is correct |
41 |
Correct |
65 ms |
21520 KB |
Output is correct |
42 |
Correct |
62 ms |
21460 KB |
Output is correct |
43 |
Correct |
63 ms |
21460 KB |
Output is correct |
44 |
Correct |
68 ms |
21484 KB |
Output is correct |
45 |
Correct |
63 ms |
21484 KB |
Output is correct |
46 |
Correct |
65 ms |
21484 KB |
Output is correct |
47 |
Correct |
3 ms |
852 KB |
Output is correct |
48 |
Incorrect |
5 ms |
1236 KB |
Output isn't correct |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
5 ms |
212 KB |
Output is correct |
9 |
Correct |
5 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
212 KB |
Output is correct |
13 |
Correct |
59 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
14 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
212 KB |
Output is correct |
20 |
Correct |
49 ms |
252 KB |
Output is correct |
21 |
Correct |
65 ms |
212 KB |
Output is correct |
22 |
Correct |
5 ms |
212 KB |
Output is correct |
23 |
Correct |
63 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
4180 KB |
Output is correct |
25 |
Correct |
5 ms |
5788 KB |
Output is correct |
26 |
Correct |
26 ms |
12628 KB |
Output is correct |
27 |
Correct |
36 ms |
15316 KB |
Output is correct |
28 |
Correct |
64 ms |
21448 KB |
Output is correct |
29 |
Correct |
66 ms |
21480 KB |
Output is correct |
30 |
Correct |
64 ms |
21460 KB |
Output is correct |
31 |
Correct |
67 ms |
21460 KB |
Output is correct |
32 |
Correct |
68 ms |
21484 KB |
Output is correct |
33 |
Correct |
65 ms |
21580 KB |
Output is correct |
34 |
Correct |
2 ms |
852 KB |
Output is correct |
35 |
Incorrect |
4 ms |
1236 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |