Submission #781206

#TimeUsernameProblemLanguageResultExecution timeMemory
781206NK_Ice Hockey World Championship (CEOI15_bobek)C++17
100 / 100
182 ms16736 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) using ll = long long; template<class T> using V = vector<T>; int main() { cin.tie(0)->sync_with_stdio(0); int N; ll M; cin >> N >> M; int a = N / 2, b = N - a; V<ll> A(a), B(b); for(auto& x : A) cin >> x; for(auto& x : B) cin >> x; V<ll> SA, SB; auto get = [&](const V<ll>& X) { int n = sz(X); V<ll> S(1 << n, 0); for(int i = 1; i < (1<<n); i++) { int low = i & -i; S[i] = S[i ^ low] + X[__lg(low)]; // cout << i << " " << __lg(low) << " " << S[i] << endl; } return S; }; SA = get(A); SB = get(B); sort(begin(SA), end(SA)); sort(begin(SB), end(SB)); ll ans = 0; int r = sz(SB) - 1; for(auto x : SA) { ll left = M - x; while(r >= 0 && SB[r] > left) r--; // cout << left << " " << r << endl; ans += r + 1; } cout << ans << nl; 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...