Submission #851911

#TimeUsernameProblemLanguageResultExecution timeMemory
851911kderyloIce Hockey World Championship (CEOI15_bobek)C++17
60 / 100
1063 ms115400 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...