Submission #66042

#TimeUsernameProblemLanguageResultExecution timeMemory
66042bazsi700Ice Hockey World Championship (CEOI15_bobek)C++14
40 / 100
1087 ms62184 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long //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 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...