#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
ll n,m;
cin>>n>>m;
vector<ll> v(n);
for(auto &i:v) cin>>i;
map<ll,int> frq;
for(int mask=0;mask<(1<<(n>>1));mask++){
ll sum = 0;
for(int i=0;i<(n>>1);i++){
if((1<<i)&mask){
sum += v[i];
}
}
frq[sum] ++;
}
int prev = 0;
vector<ll> tmp;
for(auto &i : frq){
i.second += prev;
tmp.push_back(i.first);
prev = i.second;
}
int rem = n-(n>>1);
ll ans = 0;
for(int mask=0;mask<(1<<rem);mask++){
ll sum = 0;
for(int i=0;i<rem;i++){
if((1<<i)&mask){
sum += v[(n>>1)+i];
}
}
if(sum > m) continue;
int upper = upper_bound(tmp.begin(),tmp.end(),m-sum) - tmp.begin();
upper --;
ans += frq[tmp[upper]];
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
1236 KB |
Output is correct |
2 |
Correct |
294 ms |
13028 KB |
Output is correct |
3 |
Execution timed out |
1091 ms |
33144 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1872 KB |
Output is correct |
2 |
Correct |
66 ms |
4052 KB |
Output is correct |
3 |
Correct |
188 ms |
1140 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
320 KB |
Output is correct |
6 |
Correct |
23 ms |
2416 KB |
Output is correct |
7 |
Correct |
26 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
8132 KB |
Output is correct |
2 |
Correct |
406 ms |
9184 KB |
Output is correct |
3 |
Correct |
352 ms |
9272 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
65 ms |
212 KB |
Output is correct |
6 |
Correct |
262 ms |
1856 KB |
Output is correct |
7 |
Correct |
189 ms |
18908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
37364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
5060 KB |
Output is correct |
2 |
Correct |
349 ms |
18808 KB |
Output is correct |
3 |
Correct |
18 ms |
2656 KB |
Output is correct |
4 |
Correct |
22 ms |
2676 KB |
Output is correct |
5 |
Correct |
78 ms |
324 KB |
Output is correct |
6 |
Correct |
36 ms |
4948 KB |
Output is correct |
7 |
Execution timed out |
1018 ms |
74248 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
74236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |