Submission #1121760

#TimeUsernameProblemLanguageResultExecution timeMemory
1121760vjudge1Ice Hockey World Championship (CEOI15_bobek)C++17
100 / 100
433 ms22964 KiB
// Author: RufatM #include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1e9+7 #define ll long long #define ull unsigned long long #define vi vector<int> #define vii vector<vector<int>> #define mii map<int,int> #define pb push_back #define pii pair<ll,int> #define all(a) a.begin(), a.end() #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); signed main() { fastio; int t = 1; // cin >> t; while (t--) { int N; ll M; cin >> N >> M; vector<ll> cost(N); for (int i = 0; i < N;i++) cin >> cost[i]; int n1 = N / 2, n2 = N - n1; vector<ll> left, right; for (int mask = 0; mask < (1 << n1); mask++) { ll sum = 0; for (int i = 0; i < n1; ++i) { if (mask & (1 << i)) sum += cost[i]; } left.pb(sum); } for (int mask = 0; mask < (1 << n2);mask++) { ll sum = 0; for (int i = 0; i < n2; ++i) { if (mask & (1 << i)) sum += cost[n1 + i]; } right.pb(sum); } sort(all(right)); ll total = 0; for (ll s : left) { if (s > M) continue; ll rem = M - s; ll cnt = upper_bound(all(right), rem) - right.begin(); total += cnt; } cout << total << '\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...