# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054130 | vako_p | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 902 ms | 78544 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN = 50;
ll n,m,a[mxN];
int _p[2000000];
int* p = _p + 5;
map<ll,int> ans;
vector<ll> v;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
v.pb(0);
ans[0]++;
for(int bit = 1; bit < (1 << (n / 2)); bit++){
ll x = 0;
for(int i = 0; i < (n / 2); i++) x += a[i] * (((1 << i) & bit) > 0);
if(x <= m){
if(!ans[x]) v.pb(x);
ans[x]++;
}
// cout << x << ' ' << ans[x] << '\n';
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++) p[i] = p[i - 1] + ans[v[i]];
ll res = p[v.size() - 1];
for(int bit = 1; bit < (1 << ((n + 1) / 2)); bit++){
ll x = 0;
for(int i = 0; i < (n + 1) / 2; i++) x += a[i + n / 2] * (((1 << i) & bit) > 0);
auto it = upper_bound(v.begin(), v.end(), m - x);
if(it != v.begin()) res += p[it - v.begin() - 1];
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |