#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define inf 2e18
#define fast_cin() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define out(file) freopen(file, "w", stdout)
#define in(file) freopen(file, "r", stdin)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
int MOD = 1e9 + 7;
const int N = 2001;
int y[N], a, b, n;
ll ps[N], dp[N][N];
void sub1() {
ll ans = inf;
for(int mask = 0; mask < (1 << n); mask++) {
if(((mask >> (n-1)) & 1) == 0) continue;
int cnt = __builtin_popcount(mask);
if(cnt < a or cnt > b) continue;
ll s = 0;
ll cur = 0;
// cerr << "CNT " << cnt << ln;
for(int i = 0; i < n; i++) {
s += y[i+1];
if((mask >> i) & 1) {
cur |= s;
// cerr << s << ' ';
s = 0;
}
}
// cerr << ln;
ans = min(ans, cur);
}
cout << ans;
}
bool f[51][51][1005];
void sub2() {
f[0][0][0] = 1;
for(int i = 1; i <= n; i++) {
f[i][1][ps[i]] = 1;
}
int mx = ps[n];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= b; j++) {
for(int k = 0; k <= mx; k++) {
for(int t = i + 1; t <= n; t++) {
f[t][j+1][k | (ps[t]-ps[i])] = f[t][j+1][k | (ps[t]-ps[i])] || f[i][j][k];
}
}
}
}
for(int k = 0; k <= mx; k++) {
for(int i = a; i <= b; i++) {
if(f[n][i][k]) {
cout << k;
return;
}
}
}
}
int g[101][2001];
void sub3() {
g[0][0] = 1;
int mx = ps[n];
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= mx; j++) {
g[i][j] = b + 1;
}
}
for(int i = 1; i <= n; i++) g[i][ps[i]] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= mx; j++) {
for(int t = i + 1; t <= n; t++) {
int cur = j | (ps[t] - ps[i]);
g[t][cur] = min(g[t][cur], g[i][j] + 1);
}
}
}
for(int i = 0; i <= mx; i++) {
if(g[n][i] <= b) {
cout << i;
return;
}
}
}
signed main() {
fast_cin();
cin >> n >> a >> b;
for(int i = 1; i <= n; i++) cin >> y[i], ps[i] = ps[i-1] + y[i];
// if(n <= 20) sub1();
if(n <= 20) sub1();
else if(n <= 50) sub2();
else if(n <= 100 and a == 1) sub3();
// cout << ln;
// sub2();
// sub3();
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
476 KB |
Output is correct |
22 |
Correct |
4 ms |
460 KB |
Output is correct |
23 |
Correct |
4 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
26 ms |
476 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
4 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
26 ms |
348 KB |
Output is correct |
34 |
Correct |
29 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
33 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
464 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
472 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
348 KB |
Output is correct |
22 |
Correct |
4 ms |
348 KB |
Output is correct |
23 |
Correct |
4 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
472 KB |
Output is correct |
26 |
Correct |
26 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
6 ms |
4824 KB |
Output is correct |
31 |
Correct |
19 ms |
4572 KB |
Output is correct |
32 |
Correct |
20 ms |
2908 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
10 ms |
4560 KB |
Output is correct |
35 |
Correct |
12 ms |
4444 KB |
Output is correct |
36 |
Correct |
7 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
476 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2508 KB |
Output is correct |
16 |
Correct |
3 ms |
2400 KB |
Output is correct |
17 |
Correct |
6 ms |
4576 KB |
Output is correct |
18 |
Correct |
20 ms |
4580 KB |
Output is correct |
19 |
Correct |
21 ms |
4560 KB |
Output is correct |
20 |
Correct |
2 ms |
4452 KB |
Output is correct |
21 |
Correct |
11 ms |
3048 KB |
Output is correct |
22 |
Correct |
12 ms |
2912 KB |
Output is correct |
23 |
Correct |
8 ms |
2836 KB |
Output is correct |
24 |
Correct |
2 ms |
2652 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
4 ms |
2652 KB |
Output is correct |
27 |
Correct |
6 ms |
2648 KB |
Output is correct |
28 |
Correct |
7 ms |
2696 KB |
Output is correct |
29 |
Correct |
20 ms |
2692 KB |
Output is correct |
30 |
Correct |
14 ms |
2652 KB |
Output is correct |
31 |
Correct |
10 ms |
1372 KB |
Output is correct |
32 |
Correct |
11 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
40 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
472 KB |
Output is correct |
22 |
Correct |
4 ms |
344 KB |
Output is correct |
23 |
Correct |
4 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
29 ms |
464 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
472 KB |
Output is correct |
31 |
Correct |
4 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
27 ms |
464 KB |
Output is correct |
34 |
Correct |
32 ms |
452 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
35 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
3 ms |
4444 KB |
Output is correct |
40 |
Correct |
5 ms |
4444 KB |
Output is correct |
41 |
Correct |
20 ms |
4444 KB |
Output is correct |
42 |
Correct |
32 ms |
4444 KB |
Output is correct |
43 |
Correct |
2 ms |
4440 KB |
Output is correct |
44 |
Correct |
12 ms |
4556 KB |
Output is correct |
45 |
Correct |
12 ms |
2984 KB |
Output is correct |
46 |
Correct |
7 ms |
4444 KB |
Output is correct |
47 |
Correct |
2 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2652 KB |
Output is correct |
49 |
Correct |
4 ms |
2652 KB |
Output is correct |
50 |
Correct |
6 ms |
2504 KB |
Output is correct |
51 |
Correct |
8 ms |
1116 KB |
Output is correct |
52 |
Correct |
20 ms |
2696 KB |
Output is correct |
53 |
Correct |
14 ms |
2648 KB |
Output is correct |
54 |
Correct |
8 ms |
2652 KB |
Output is correct |
55 |
Correct |
9 ms |
2652 KB |
Output is correct |
56 |
Runtime error |
67 ms |
70956 KB |
Execution killed with signal 11 |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
356 KB |
Output is correct |
9 |
Correct |
2 ms |
360 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
480 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
30 ms |
476 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
6 ms |
468 KB |
Output is correct |
19 |
Correct |
3 ms |
344 KB |
Output is correct |
20 |
Correct |
26 ms |
348 KB |
Output is correct |
21 |
Correct |
31 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
30 ms |
472 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
4576 KB |
Output is correct |
27 |
Correct |
6 ms |
4444 KB |
Output is correct |
28 |
Correct |
21 ms |
4440 KB |
Output is correct |
29 |
Correct |
20 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
2392 KB |
Output is correct |
31 |
Correct |
11 ms |
4576 KB |
Output is correct |
32 |
Correct |
12 ms |
4444 KB |
Output is correct |
33 |
Correct |
7 ms |
4564 KB |
Output is correct |
34 |
Correct |
2 ms |
2648 KB |
Output is correct |
35 |
Correct |
3 ms |
2652 KB |
Output is correct |
36 |
Correct |
4 ms |
2652 KB |
Output is correct |
37 |
Correct |
7 ms |
2652 KB |
Output is correct |
38 |
Correct |
8 ms |
2652 KB |
Output is correct |
39 |
Correct |
14 ms |
2652 KB |
Output is correct |
40 |
Correct |
14 ms |
2700 KB |
Output is correct |
41 |
Correct |
8 ms |
2652 KB |
Output is correct |
42 |
Correct |
9 ms |
2696 KB |
Output is correct |
43 |
Runtime error |
41 ms |
70944 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |