Submission #40670

#TimeUsernameProblemLanguageResultExecution timeMemory
40670MatheusLealVIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
619 ms17596 KiB
#include <bits/stdc++.h> #define N 41 using namespace std; typedef long long ll; ll n, v[N], ans, k; vector<ll> val; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i = 0; i < n; i++) cin>>v[i]; int m = n/2; for(int mask = 1; mask <= ( (1<<(m + 1)) - 1) ; mask ++) { ll sum = 0; for(int i = 0; i <= m; i++) { if( (mask & (1<<i)) ) { sum += v[i]; } } if(sum <= k) ans ++; val.push_back(sum); } sort(val.begin(), val.end()); for(int mask = 1; mask <= ( (1<<(n - m - 1)) - 1) ; mask ++) { ll sum = 0; for(int i = m + 1; i < n; i++) { int j = i - m - 1; if( (mask & (1<<j)) ) { sum += v[i]; } } if(sum <= k) { //cout<<sum<<" "<< (upper_bound(val.begin(), val.end(), k - sum) - val.begin())<<"\n"; ans += upper_bound(val.begin(), val.end(), k - sum) - val.begin() + 1; } } cout<<ans + 1<<"\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...