Submission #259227

#TimeUsernameProblemLanguageResultExecution timeMemory
259227vioalbertIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
293 ms33476 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 45, MAX = 20; ll n, m, border; ll a[N]; ll dp1[(1<<MAX)], dp2[(1<<MAX)]; vector<ll> v1, v2; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; border = (n+1)/2; for(int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a+n, greater<ll>()); for(int i = 0; i < border; i++) dp1[(1<<i)] = a[i]; dp1[0] = 0; for(ll mask = 0; mask < (1<<border); mask++) { if(__builtin_popcount(mask) > 1) { int x = mask&(-mask); dp1[mask] = dp1[x] + dp1[mask^x]; } if(dp1[mask] <= m) { v1.push_back(dp1[mask]); } } for(int i = border; i < n; i++) dp2[(1<<(i-border))] = a[i]; dp2[0] = 0; for(ll mask = 0; mask < (1<<(n-border)); mask++) { if(__builtin_popcount(mask) > 1) { int x = mask&(-mask); dp2[mask] = dp2[x] + dp2[mask^x]; } if(dp2[mask] <= m) { v2.push_back(dp2[mask]); } } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); ll ans = 0; for(ll x : v1) { ll len = upper_bound(v2.begin(), v2.end(), m - x) - v2.begin(); ans += len; } cout << ans << '\n'; 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...