제출 #638768

#제출 시각아이디문제언어결과실행 시간메모리
638768HossamHero7Ice Hockey World Championship (CEOI15_bobek)C++14
60 / 100
1089 ms74312 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' void solve(){ int n; ll m; cin>>n>>m; vector<ll> v(n); for(auto &i:v) cin>>i; map<ll,ll> frq; for(int mask=0;mask<(1<<n/2);mask++){ ll sum = 0; for(int i=0;i<n/2;i++){ if((1<<i)&mask){ sum += v[i]; } } frq[sum] ++; } ll prev = 0; vector<ll> tmp; for(auto &i : frq){ i.second += prev; tmp.push_back(i.first); prev = i.second; } int rem = n-n/2; ll ans = 0; for(int mask=0;mask<(1<<rem);mask++){ ll sum = 0; for(int i=0;i<rem;i++){ if((1<<i)&mask){ sum += v[n/2+i]; } } if(sum > m) continue; int upper = upper_bound(tmp.begin(),tmp.end(),m-sum) - tmp.begin(); upper --; ans += frq[tmp[upper]]; } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } 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...