Submission #208156

#TimeUsernameProblemLanguageResultExecution timeMemory
208156HeydarBABAIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
221 ms16888 KiB
#include<bits/stdc++.h> using namespace std; const long long maxn = 40; const long long maxc = (1 << 20) + 10; long long A, B; long long n, m; long long a[maxn]; long long b[maxn]; long long a2[maxc]; long long b2[maxc]; long long ans; void in(); void solve(); void out(); int main(){ in(); solve(); out(); } void in(){ ios::sync_with_stdio(false); cin >> n >> m; for(long long i = 0; i < n / 2; i++) cin >> a[i + 1]; A = n / 2; for(long long i = n / 2; i < n; i++) cin >> b[i - n / 2 + 1]; B = n - A; } void solve(){ for(long long i = 1; i < (1 << A); i++){ a2[i] = a2[i - (i & -i)]; a2[i] += a[__builtin_ctz(i) + 1]; } for(long long i = 1; i < (1 << B); i++){ b2[i] = b2[i - (i & -i)]; b2[i] += b[__builtin_ctz(i) + 1]; } sort(a2, a2 + (1 << A)); sort(b2, b2 + (1 << B)); A = 1 << A; B = 1 << B; long long nowb = B - 1; for(long long i = 0; i < A; i++){ while(nowb != -1 && b2[nowb] + a2[i] > m) nowb--; ans += nowb + 1; } } void out(){ cout << ans; }
#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...