This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//14:20
int n;
ll m;
ll c[45];
ll way[1050000];
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> compr;
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) {
did.insert(m-money);
}
}
int in = 1;
for(ll el : did) {
compr[el] = in++;
}
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) {
way[compr[(m-money)]]++;
}
}
for(int i = 1; i <= in; i++) {
way[i]+=way[i-1];
}
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+= way[compr[*it]];
}
}
}
cout << ways;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |