#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#pragma GCC optimize("O2")
void solve(){
ll n,m;
cin>>n>>m;
vector<ll> v(n);
for(auto &i:v) cin>>i;
unordered_map<ll,int> frq;
for(int mask=0;mask<(1<<n/2);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){
tmp.push_back(i.first);
}
sort(tmp.begin(),tmp.end());
for(auto i : tmp){
frq[i] += prev;
prev = frq[i];
}
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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1100 KB |
Output is correct |
2 |
Correct |
153 ms |
9956 KB |
Output is correct |
3 |
Correct |
746 ms |
27824 KB |
Output is correct |
4 |
Correct |
149 ms |
12116 KB |
Output is correct |
5 |
Correct |
9 ms |
328 KB |
Output is correct |
6 |
Correct |
6 ms |
596 KB |
Output is correct |
7 |
Correct |
23 ms |
4068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1436 KB |
Output is correct |
2 |
Correct |
37 ms |
3428 KB |
Output is correct |
3 |
Correct |
96 ms |
928 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
316 KB |
Output is correct |
6 |
Correct |
16 ms |
1972 KB |
Output is correct |
7 |
Correct |
27 ms |
3940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
6820 KB |
Output is correct |
2 |
Correct |
184 ms |
7476 KB |
Output is correct |
3 |
Correct |
192 ms |
7644 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
58 ms |
296 KB |
Output is correct |
6 |
Correct |
149 ms |
1424 KB |
Output is correct |
7 |
Correct |
144 ms |
15360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
916 ms |
30436 KB |
Output is correct |
2 |
Correct |
46 ms |
4068 KB |
Output is correct |
3 |
Correct |
16 ms |
1968 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
420 ms |
30472 KB |
Output is correct |
7 |
Correct |
25 ms |
4080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
4072 KB |
Output is correct |
2 |
Correct |
219 ms |
15264 KB |
Output is correct |
3 |
Correct |
16 ms |
2080 KB |
Output is correct |
4 |
Correct |
16 ms |
1968 KB |
Output is correct |
5 |
Correct |
63 ms |
308 KB |
Output is correct |
6 |
Correct |
31 ms |
4032 KB |
Output is correct |
7 |
Correct |
779 ms |
60780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
60868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |