Submission #555445

#TimeUsernameProblemLanguageResultExecution timeMemory
555445hidden1Ice Hockey World Championship (CEOI15_bobek)C++14
100 / 100
524 ms17000 KiB
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") #ifndef LOCAL #define cerr if(false) cerr #endif #define endl "\n" #define out(x) "[" << #x << "=" << x << "]" struct debug { debug() { cerr << "DEBUGGER: " << endl; } ~debug() { cerr << endl << "DEBUGGER_END " << endl; } template<class T> debug& operator <<(const T x) { cerr << x << " "; return *this; } }; template<class T> inline ostream &operator <<(ostream &out, const vector<T> &x) { for(const auto &it : x) { out << it << " "; } return out; } template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { return out << x.first << " " << x.second; } template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } typedef long long ll; const ll mod = 1e9 + 7; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// const ll MAX_N = 1e5 + 10; vector<ll> st; ll n; ll m; ll arr[MAX_N]; void solveLeft(ll l, ll r) { for(ll mask = 0; mask < (1 << (r - l + 1)); mask ++) { ll sum = 0; for(ll j = l; j <= r; j ++) { if(mask & (1 << (j - l))) { sum += arr[j]; } } st.push_back(sum); } sort(st.begin(), st.end()); for(auto it : st) { cerr << it << " "; } cerr << endl; } ll ret = 0; void solveRght(ll l, ll r) { for(ll mask = 0; mask < (1 << (r - l + 1)); mask ++) { ll sum = 0; for(ll j = l; j <= r; j ++) { if(mask & (1 << (j - l))) { sum += arr[j]; } } cerr << "Adding " << sum << " " << (lower_bound(st.begin(), st.end(), m - sum + 1) - st.begin()) << endl; ret += (lower_bound(st.begin(), st.end(), m - sum + 1) - st.begin()); } } signed main() { #ifndef LOCAL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #endif cin >> n >> m; for(int i = 0; i < n; i ++) { cin >> arr[i]; } solveLeft(0, n / 2); solveRght(n / 2 + 1, n - 1); cout << ret << endl; 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...