Submission #874363

#TimeUsernameProblemLanguageResultExecution timeMemory
874363bobbilykingIce Hockey World Championship (CEOI15_bobek)C++17
100 / 100
182 ms16872 KiB
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<math.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pl; #define K first #define V second #define G(x) ll x; cin >> x; #define GD(x) ld x; cin >> x; #define GS(s) string s; cin >> s; #define EX(x) { cout << x << '\n'; exit(0); } #define A(a) (a).begin(), (a).end() #define F(i, l, r) for (ll i = (l); i < r; ++i) #define NN #define M 1000000007 // 998244353 int main(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); G(n) G(k) vector<ll> v(n); for (auto &x: v) cin >> x; if (n == 1){ cout << 1 + (v[0] <= k)* v[0] << '\n'; exit(0); } ll hlf = n/2; vector<ll> th(1<<hlf); F(bm, 0, 1<<(hlf)) { ll s = 0; F(i, 0, hlf) if ((1<<i)&bm) s += v[n-hlf+i]; th[bm] = s; } hlf = n-hlf; vector<ll> th2(1<<hlf); F(bm, 0, 1<<hlf) { ll s = 0; F(i, 0, hlf) if ((1<<i)&bm) s += v[i]; th2[bm] = s; } sort(A(th)); sort(A(th2)); ll rp = th2.size()-1; ll ans = 0; for (const auto &x: th) { while (rp >= 0 and x + th2[rp] > k) --rp; ans += rp+1; } 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...