Submission #759213

#TimeUsernameProblemLanguageResultExecution timeMemory
759213sofija6Ice Hockey World Championship (CEOI15_bobek)C++14
60 / 100
1085 ms161152 KiB
#include <bits/stdc++.h> #define ll long long #define MAXN 50 using namespace std; ll a[MAXN],m,l,r; set<ll> s1,s2; map<ll,ll> cnt1,cnt2; void Solve_1(ll cur,ll pos) { if (pos>r) { if (cur>m) return; s1.insert(cur); cnt1[cur]++; return; } Solve_1(cur,pos+1); Solve_1(cur+a[pos],pos+1); } void Solve_2(ll cur,ll pos) { if (pos>r) { if (cur>m) return; s2.insert(cur); cnt2[cur]++; return; } Solve_2(cur,pos+1); Solve_2(cur+a[pos],pos+1); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,ans=0; cin >> n >> m; for (ll i=1;i<=n;i++) cin >> a[i]; l=1; r=n/2; Solve_1(0,1); l=n/2+1; r=n; Solve_2(0,n/2+1); ll cur=0; for (auto i : s2) { cur+=cnt2[i]; cnt2[i]=cur; } for (auto i : s1) { auto it=s2.lower_bound(m-i); if ((*it)!=m-i) { if (it==s2.begin()) continue; it--; } ans+=cnt1[i]*cnt2[*it]; } cout << ans; 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...