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;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1;
int r = bm(b, p/2);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int f[MAXN];
int nCr(int n, int r) {
int ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() {
f[0] = 1;
for(int i=1; i<MAXN; i++) f[i] = (f[i-1] * i) % MOD;
}
void solve(int tc) {
int n, m;
cin >> n >> m;
vector<int> l, r;
for(int i=0; i<n/2; i++) {
int x;cin >> x;
l.push_back(x);
}
for(int i=0; i<n-n/2; i++) {
int x;cin >> x;
r.push_back(x);
}
vector<int> v;
int L = l.size();
for(int i=0; i<(1<<L); i++) {
int e = 0;
for(int j=0; j<L; j++) {
if(i & (1<<j)) {
e += l[j];
}
}
v.push_back(e);
}
sort(v.begin(), v.end());
int R = r.size();
int ans = 0;
for(int i=0; i<(1<<R); i++) {
int e = 0;
for(int j=0; j<R; j++) {
if(i & (1<<j)) {
e += r[j];
}
}
int lb = 0, rb = v.size() - 1;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(v[mid] + e <= m) lb = mid;
else rb = mid - 1;
}
if(v[lb] + e <= m) ans += lb + 1;
}
cout << ans << "\n";
}
int32_t main(){
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# | 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... |