Submission #208167

#TimeUsernameProblemLanguageResultExecution timeMemory
208167SMani24Ice Hockey World Championship (CEOI15_bobek)C++11
100 / 100
272 ms16888 KiB
//In the name of Allah //SMani24 #include<bits/stdc++.h> #define debug(x) cerr << #x << " = " << x << endl #define int long long using namespace std; const int N = 42; int n, m, ans; int a[N], dpu[1 << (N / 2)], dpd[1 << (N / 2)], prep[1 << (N / 2)]; void set_prep() { for (int i = 0; i < N / 2; i++) prep[1 << i] = i; } void read_input() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; } void solve() { set_prep(); int nu = n / 2, nd = (n + 1) / 2; for (int mask = 1; mask < (1 << nu); mask++) dpu[mask] = dpu[mask ^ (mask & -mask)] + a[prep[mask & -mask]]; for (int mask = 1; mask < (1 << nd); mask++) dpd[mask] = dpd[mask ^ (mask & -mask)] + a[prep[mask & -mask] + nu]; sort(dpu, dpu + (1 << nu)); sort(dpd, dpd + (1 << nd)); for (int i = 0; i < (1 << nu); i++) { if (dpu[i] > m) break; ans += upper_bound(dpd, dpd + (1 << nd), m - dpu[i]) - dpd; } } void write_output() { cout << ans << endl; } int32_t main() { ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0); read_input(), solve(), write_output(); 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...