#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1<<9, maxk = 101, lg = 21, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
vector<ll> slv(vector<ll> a){
vector<ll> res{0}; int n = sz(a);
rep(i,1,1<<n){
int f = __builtin_ctz(i);
res.pb(res[i^(1<<f)] + a[f]);
}
sort(all(res));
return res;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
ll n, m; cin >> n >> m;
vector<ll> a(n);
rep(i,0,n) cin >> a[i];
vector<ll> resl = slv(vector<ll>(begin(a), begin(a) + (n>>1))), resr = slv(vector<ll>(begin(a) + (n>>1), end(a)));
ll ans = 0, ptr = sz(resr)-1;
for(ll c: resl){
if(c > m) break;
while(c + resr[ptr] > m) ptr--;
ans += ptr + 1;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2008 KB |
Output is correct |
2 |
Correct |
46 ms |
5468 KB |
Output is correct |
3 |
Correct |
188 ms |
20844 KB |
Output is correct |
4 |
Correct |
44 ms |
5364 KB |
Output is correct |
5 |
Correct |
6 ms |
1620 KB |
Output is correct |
6 |
Correct |
4 ms |
984 KB |
Output is correct |
7 |
Correct |
10 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2896 KB |
Output is correct |
2 |
Correct |
16 ms |
2136 KB |
Output is correct |
3 |
Correct |
66 ms |
10552 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
984 KB |
Output is correct |
6 |
Correct |
9 ms |
1492 KB |
Output is correct |
7 |
Correct |
10 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3548 KB |
Output is correct |
2 |
Correct |
67 ms |
6608 KB |
Output is correct |
3 |
Correct |
64 ms |
6608 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
31 ms |
6620 KB |
Output is correct |
6 |
Correct |
140 ms |
20832 KB |
Output is correct |
7 |
Correct |
63 ms |
6616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
12748 KB |
Output is correct |
2 |
Correct |
15 ms |
2008 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
984 KB |
Output is correct |
6 |
Correct |
139 ms |
12708 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2008 KB |
Output is correct |
2 |
Correct |
43 ms |
5436 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
5 ms |
968 KB |
Output is correct |
5 |
Correct |
35 ms |
6596 KB |
Output is correct |
6 |
Correct |
14 ms |
2008 KB |
Output is correct |
7 |
Correct |
183 ms |
20816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
181 ms |
20756 KB |
Output is correct |
2 |
Correct |
15 ms |
2012 KB |
Output is correct |
3 |
Correct |
5 ms |
984 KB |
Output is correct |
4 |
Correct |
186 ms |
20832 KB |
Output is correct |
5 |
Correct |
43 ms |
10584 KB |
Output is correct |
6 |
Correct |
10 ms |
1492 KB |
Output is correct |
7 |
Correct |
19 ms |
2908 KB |
Output is correct |