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 <iostream>
#include <set>
#include <map>
using namespace std;
long long tab[50];
set<long long>war;
map<long long,long long>mapka;
void calculate_values(int ile)
{
for(int i=0;i<(1<<ile);i++){
long long suma=0;
for(int j=0;j<ile;j++){
if((i&(1<<j))>0){
suma+=tab[j];
}
}
war.insert(suma);
mapka[suma]++;
}
}
long long calculate_result(int start,int rozmiar,long long limit)
{
long long wyn=0;
for(int i=0;i<(1<<rozmiar);i++){
long long suma=0;
for(int j=0;j<rozmiar;j++){
if((i&(1<<j))>0){
suma+=tab[start+j];
}
}
long long pom=limit-suma;
auto it=war.upper_bound(pom);
if(it!=war.begin()){
it--;
wyn+=mapka[*it];
}
}
return wyn;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
long long limit;
cin>>ile>>limit;
for(int i=0;i<ile;i++){
cin>>tab[i];
}
if(ile==1){
if(tab[0]<=limit){
cout<<"2";
}
else{
cout<<"1";
}
return 0;
}
calculate_values(ile/2);
auto it=war.begin();
long long l=0;
while(it!=war.end()){
l+=mapka[*it];
mapka[*it]=l;
it++;
}
cout<<calculate_result(ile/2,ile-(ile/2),limit);
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... |