Submission #854995

#TimeUsernameProblemLanguageResultExecution timeMemory
854995tvladm2009Ice Hockey World Championship (CEOI15_bobek)C++17
100 / 100
340 ms21940 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 40 + 7; ll a[N]; ll n, x; signed main() { #ifdef ONPC freopen ("input.txt", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif // ONPC cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; } int half1 = (n + 1) / 2; int half2 = n - half1; vector<ll> v1, v2; for (int mask = 0; mask < (1 << half1); mask++) { ll s = 0; for (int b = 0; b < half1; b++) { if (mask & (1 << b)) { s += a[b + 1]; } } v1.push_back(s); } for (int mask = 0; mask < (1 << half2); mask++) { ll s = 0; for (int b = 0; b < half2; b++) { if (mask & (1 << b)) { s += a[half1 + b + 1]; } } v2.push_back(s); } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); ll print = 0; for (auto &it : v1) { int low = 0, high = (int) v2.size() - 1, sol = -1; while (low <= high) { int mid = (low + high) / 2; if (v2[mid] <= x - it) { low = mid + 1; sol = mid; } else { high = mid - 1; } } print += sol + 1; } cout << print << "\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...