# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768962 | anha3k25cvp | Ice Hockey World Championship (CEOI15_bobek) | C++14 | 818 ms | 24928 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>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>
using namespace std;
const int N = 5 + 1e5;
const int inf = 7 + 1e9;
struct fenwick {
int n;
vector <ll> tree;
fenwick (int _n = 0) : n(_n) {
tree.assign(n + 1, 0);
}
void update(int x) {
for (int i = x; i <= n; i += i & -i)
tree[i] ++;
}
ll get(int x) {
ll ans = 0;
for (int i = x; i > 0; i -= i & -i)
ans += tree[i];
return ans;
}
};
int main() {
#define TASKNAME ""
ios_base :: sync_with_stdio (0);
cin.tie (0);
if ( fopen( TASKNAME".inp", "r" ) ) {
freopen (TASKNAME".inp", "r", stdin);
freopen (TASKNAME".out", "w", stdout);
}
int n;
ll m;
cin >> n >> m;
int n_ = n / 2;
vector <ll> a(n_, 0), c;
for (int i = 0; i < n_; i ++)
cin >> a[i];
for (int mask = 0; mask < (1 << n_); mask ++) {
ll sum = 0;
for (int si = mask; si > 0; si ^= si & -si) {
int i = __builtin_ctz(si & -si);
sum += a[i];
}
c.push_back(sum);
}
for (int mask = 0; mask < (1 << n_); mask ++) {
ll sum = 0;
for (int si = mask; si > 0; si ^= si & -si) {
int i = __builtin_ctz(si & -si);
sum += a[i];
}
c.push_back(sum);
}
sort(c.begin(), c.end());
c.resize(unique(c.begin(), c.end()) - c.begin());
fenwick f(c.size());
for (int mask = 0; mask < (1 << n_); mask ++) {
ll sum = 0;
for (int si = mask; si > 0; si ^= si & -si) {
int i = __builtin_ctz(si & -si);
sum += a[i];
}
sum = lower_bound(c.begin(), c.end(), sum) - c.begin() + 1;
f.update(sum);
}
n_ = n - n_;
a.assign(n_, 0);
for (int i = 0; i < n_; i ++)
cin >> a[i];
ll ans = 0;
for (int mask = 0; mask < (1 << n_); mask ++) {
ll sum = 0;
for (int si = mask; si > 0; si ^= si & -si) {
int i = __builtin_ctz(si & -si);
sum += a[i];
}
sum = upper_bound(c.begin(), c.end(), m - sum) - c.begin();
ans += f.get(sum);
}
cout << ans;
return 0;
}
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... |