Submission #204468

#TimeUsernameProblemLanguageResultExecution timeMemory
204468staniewzkiIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
569 ms8788 KiB
#include<bits/stdc++.h> using namespace std; ostream& operator<<(ostream &out, string str) { for(char c : str) out << c; return out; } template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.first << ", " << p.second << ")"; } template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << "{"; for(auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << "}"; } void dump() { cerr << "\n"; } template<class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #ifdef DEBUG # define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else # define debug(...) false #endif #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define ST first #define ND second template<class T> int size(T && a) { return a.size(); } using LL = long long; using PII = pair<int, int>; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; LL m; cin >> n >> m; vector<LL> a(n); REP(i, n) cin >> a[i]; vector<LL> left; REP(i, (1 << (n / 2))) { LL sum = 0; REP(j, n / 2) { if(i & (1 << j)) sum += a[j]; } left.emplace_back(sum); } sort(left.begin(), left.end()); LL ans = 0; REP(i, (1 << ((n + 1) / 2))) { LL sum = 0; FOR(j, n / 2, n - 1) { if(i & (1 << (j - n / 2))) sum += a[j]; } auto it = upper_bound(left.begin(), left.end(), m - sum); ans += distance(left.begin(), it); } 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...