#include <bits/stdc++.h>
using namespace std;
#define ll long long
//14:20
int n;
ll m;
ll c[45];
ll way[2150000];
unordered_map<ll,int> compr;
vector<ll> did;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) {
cin >> c[i];
}
if(n <= 22) {
ll ways = 0;
for(int mask = 0; mask < (1<<n); mask++) {
ll money = m;
for(int i = 0; i < n; i++) {
if(mask&(1<<i)) {
money-= c[i];
}
}
if(money >= 0) {
ways++;
}
}
cout << ways;
} else {
ll ways = 0;
int b1 = 19;
for(int mask = 0; mask < (1<<b1); mask++) {
ll money = m;
for(int i = 0; i < b1; i++) {
if(mask&(1<<i)) {
money-= c[i];
}
}
if(money >= 0) {
did.push_back(m-money);
}
}
sort(did.begin(),did.end());
int in = 1;
ll prev = -1;
for(ll el : did) {
if(el != prev) {
way[in]++;
compr[el] = in++;
prev = el;
} else {
way[in-1]++;
}
}
for(int i = 1; i <= in; i++) {
way[i]+=way[i-1];
}
for(int mask = 0; mask < (1<<(n-b1)); mask++) {
ll money = m;
for(int i = b1; i < n; i++) {
if(mask&(1<<(i-b1))) {
money-= c[i];
}
}
if(money >= 0) {
auto it = upper_bound(did.begin(),did.end(),money);
if(it != did.begin()) {
it--;
ways+= way[compr[*it]];
}
}
}
cout << ways;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
488 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
640 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
696 KB |
Output is correct |
7 |
Correct |
3 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
696 KB |
Output is correct |
2 |
Correct |
7 ms |
744 KB |
Output is correct |
3 |
Correct |
13 ms |
744 KB |
Output is correct |
4 |
Correct |
4 ms |
744 KB |
Output is correct |
5 |
Correct |
9 ms |
744 KB |
Output is correct |
6 |
Correct |
86 ms |
748 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
748 KB |
Output is correct |
2 |
Correct |
25 ms |
748 KB |
Output is correct |
3 |
Correct |
8 ms |
748 KB |
Output is correct |
4 |
Correct |
7 ms |
748 KB |
Output is correct |
5 |
Correct |
83 ms |
748 KB |
Output is correct |
6 |
Correct |
12 ms |
748 KB |
Output is correct |
7 |
Correct |
11 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
5476 KB |
Output is correct |
2 |
Correct |
294 ms |
18660 KB |
Output is correct |
3 |
Execution timed out |
1085 ms |
21216 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
21216 KB |
Output is correct |
2 |
Correct |
174 ms |
21216 KB |
Output is correct |
3 |
Correct |
272 ms |
21216 KB |
Output is correct |
4 |
Correct |
3 ms |
21216 KB |
Output is correct |
5 |
Correct |
68 ms |
21216 KB |
Output is correct |
6 |
Correct |
107 ms |
21216 KB |
Output is correct |
7 |
Correct |
47 ms |
21216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
21216 KB |
Output is correct |
2 |
Correct |
334 ms |
21216 KB |
Output is correct |
3 |
Correct |
316 ms |
21216 KB |
Output is correct |
4 |
Correct |
21 ms |
21216 KB |
Output is correct |
5 |
Correct |
115 ms |
21216 KB |
Output is correct |
6 |
Correct |
397 ms |
21216 KB |
Output is correct |
7 |
Correct |
70 ms |
21216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
32784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
32784 KB |
Output is correct |
2 |
Correct |
646 ms |
32868 KB |
Output is correct |
3 |
Correct |
443 ms |
32868 KB |
Output is correct |
4 |
Correct |
457 ms |
32868 KB |
Output is correct |
5 |
Correct |
125 ms |
32868 KB |
Output is correct |
6 |
Correct |
472 ms |
32868 KB |
Output is correct |
7 |
Correct |
202 ms |
32868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
32868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |