#include <iostream>
#include <string.h>
using namespace std;
#define int long long
#define pc __builtin_popcount
const int N = 21, inf = 1e18;
int n, a, b, ans = inf, ar[N], dp[1 << N];
void calc(int mask) {
if(dp[mask] != -1) {
return;
}
if(a <= pc(mask) + 1 && pc(mask) + 1 <= b) {
int sum = 0, temp = 0;
for(int i = 0; i < n; i++) {
sum += ar[i];
if(mask >> i & 1) {
temp |= sum;
sum = 0;
}
}
temp |= sum;
dp[mask] = temp;
ans = min(ans, dp[mask]);
}
int st = 0;
for(int i = st; i < n; i++) {
if(mask >> i & 1); else {
calc(1 << i | mask);
}
}
}
main() {
cin >> n >> a >> b;
memset(dp, -1, sizeof dp);
for(int i = 0; i < n; i++) {
cin >> ar[i];
}
calc(0);
cout << ans << endl;
}
Compilation message
sculpture.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16740 KB |
Output is correct |
2 |
Correct |
15 ms |
16768 KB |
Output is correct |
3 |
Correct |
14 ms |
16768 KB |
Output is correct |
4 |
Correct |
16 ms |
16896 KB |
Output is correct |
5 |
Correct |
223 ms |
16860 KB |
Output is correct |
6 |
Correct |
22 ms |
16768 KB |
Output is correct |
7 |
Execution timed out |
1077 ms |
16768 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
16768 KB |
Output is correct |
2 |
Correct |
17 ms |
16768 KB |
Output is correct |
3 |
Correct |
17 ms |
16740 KB |
Output is correct |
4 |
Correct |
17 ms |
16768 KB |
Output is correct |
5 |
Correct |
240 ms |
16772 KB |
Output is correct |
6 |
Correct |
20 ms |
16768 KB |
Output is correct |
7 |
Execution timed out |
1079 ms |
16768 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
16708 KB |
Output is correct |
2 |
Correct |
16 ms |
16768 KB |
Output is correct |
3 |
Correct |
16 ms |
16768 KB |
Output is correct |
4 |
Correct |
15 ms |
16768 KB |
Output is correct |
5 |
Correct |
218 ms |
16888 KB |
Output is correct |
6 |
Correct |
20 ms |
16768 KB |
Output is correct |
7 |
Execution timed out |
1073 ms |
16768 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
16768 KB |
Output is correct |
2 |
Correct |
17 ms |
16768 KB |
Output is correct |
3 |
Correct |
16 ms |
16768 KB |
Output is correct |
4 |
Correct |
17 ms |
16768 KB |
Output is correct |
5 |
Correct |
214 ms |
16768 KB |
Output is correct |
6 |
Correct |
18 ms |
16768 KB |
Output is correct |
7 |
Execution timed out |
1076 ms |
16768 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
16764 KB |
Output is correct |
2 |
Correct |
16 ms |
16768 KB |
Output is correct |
3 |
Correct |
16 ms |
16768 KB |
Output is correct |
4 |
Correct |
15 ms |
16768 KB |
Output is correct |
5 |
Correct |
209 ms |
16804 KB |
Output is correct |
6 |
Correct |
18 ms |
16768 KB |
Output is correct |
7 |
Execution timed out |
1062 ms |
16768 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |