Submission #384168

#TimeUsernameProblemLanguageResultExecution timeMemory
384168SortingIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
546 ms8796 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> void check_min(T &a, const T & b){ a = (a < b) ? a : b; } template<typename T> void check_max(T &a, const T & b){ a = (a > b) ? a : b; } const int N = 40 + 3; int n; ll m, a[N]; vector<ll> v; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 0; i < n; ++i) cin >> a[i]; int half = n / 2; for(int mask = 0; mask < (1 << half); ++mask){ ll sum = 0; for(int i = 0; i < half; ++i) if(mask & (1 << i)) sum += a[i]; v.push_back(sum); } sort(v.begin(), v.end()); ll ans = 0; for(int mask = 0; mask < (1 << (n - half)); ++mask){ ll sum = 0; for(int i = half; i < n; ++i) if(mask & (1 << (i - half))) sum += a[i]; ans += upper_bound(v.begin(), v.end(), m - sum) - v.begin(); } cout << ans << "\n"; }
#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...