#include <bits/stdc++.h>
using namespace std;
#define ll int
//14:20
int n;
ll m;
ll c[45];
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 <= 21) {
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;
set<ll> did;
map<ll,int> did1;
map<ll,int> did2;
for(int mask = 0; mask < (1<<20); mask++) {
ll money = m;
for(int i = 0; i < 20; i++) {
if(mask&(1<<i)) {
money-= c[i];
}
}
if(money >= 0) {
did1[m-money]++;
did.insert(m-money);
}
}
ll prev = -1;
for(int el : did) {
if(prev != -1) {
did2[el] = prev = did1[el]+prev;
} else {
did2[el] = prev = did1[el];
}
}
for(int mask = 0; mask < (1<<(n-20)); mask++) {
ll money = m;
for(int i = 20; i < n; i++) {
if(mask&(1<<(i-20))) {
money-= c[i];
}
}
if(money >= 0) {
auto it = did.upper_bound(money);
if(it != did.begin()) {
it--;
ways+= did2[*it];
}
}
}
cout << ways;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
356 KB |
Output is correct |
2 |
Correct |
2 ms |
432 KB |
Output is correct |
3 |
Correct |
3 ms |
480 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 |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
559 ms |
3040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
598 ms |
4600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
37644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
131 ms |
37644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
37644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
180 ms |
37644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |