Submission #870370

#TimeUsernameProblemLanguageResultExecution timeMemory
870370vjudge1Ice Hockey World Championship (CEOI15_bobek)C++17
100 / 100
428 ms10664 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> sums; for (int i = 0; i < (1 << (n / 2)); i++) { int sum = 0; for (int j = 0; j < n / 2; j++) if ((1 << j) & i) sum += a[j]; if (sum <= m) sums.push_back(sum); } sort(sums.begin(),sums.end()); int sz = sums.size(); int cnt = 0; for (int i = 0; i < (1 << (n - n / 2)); i++) { int sum = 0; for (int j = n/2; j < n; j++) if ((1 << (j-n/2)) & i) sum += a[j]; int l = 0, r = sz-1; while (r-l > 1) { int mid = (r+l)/2; if (sums[mid] > m-sum) r = mid; else l = mid; } if (sums[r] <= m-sum) l = r; if (sums[l] <= m-sum) cnt+=l+1; } cout << cnt << '\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...