#include<bits/stdc++.h>
using namespace std;
int N;
long long M;
long long cost[40];
void smallM(){
vector<long long int> dp(M+1, 0);
dp[0] = 1;
for(int match = 0; match < N; ++match){
for(long long val = M; val > 0; --val){
if(cost[match] <= val) dp[val] += dp[val - cost[match]];
}
}
long long ans = 0;
for(int i = 0; i <= M; ++i) ans += dp[i];
cout << ans << endl;
}
int main(){
cin >> N >> M;
for(int i = 0; i < N; ++i) cin >> cost[i];
if(N <= 20){
long long ans = 0;
for(int mask = 0; mask < (1 << N); ++mask){
long long sum = 0;
for(int i = 0; i < N; ++i){
if(mask & (1 << i))sum+= cost[i];
}
if(sum <= M) ans++;
}
cout << ans << endl;
}else{
smallM();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
212 KB |
Output is correct |
3 |
Correct |
8 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
212 KB |
Output is correct |
6 |
Correct |
62 ms |
280 KB |
Output is correct |
7 |
Correct |
8 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
284 KB |
Output is correct |
2 |
Correct |
15 ms |
300 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
212 KB |
Output is correct |
5 |
Correct |
62 ms |
276 KB |
Output is correct |
6 |
Correct |
8 ms |
212 KB |
Output is correct |
7 |
Correct |
8 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
16 ms |
4948 KB |
Output is correct |
3 |
Correct |
27 ms |
7380 KB |
Output is correct |
4 |
Correct |
16 ms |
4780 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
1620 KB |
Output is correct |
7 |
Correct |
17 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
6 ms |
2220 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
20 ms |
6996 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4416 KB |
Output is correct |
2 |
Correct |
9 ms |
2476 KB |
Output is correct |
3 |
Correct |
8 ms |
2476 KB |
Output is correct |
4 |
Correct |
15 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
14 ms |
4096 KB |
Output is correct |
7 |
Correct |
18 ms |
3976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |