#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
void solve(){
ll n,m;
cin>>n>>m;
vector<ll> v(n);
for(auto &i:v) cin>>i;
unordered_map<ll,int,custom_hash> 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 |
1 ms |
292 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 |
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 |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 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 |
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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1236 KB |
Output is correct |
2 |
Correct |
206 ms |
12660 KB |
Output is correct |
3 |
Execution timed out |
1051 ms |
35120 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
1748 KB |
Output is correct |
2 |
Correct |
43 ms |
4172 KB |
Output is correct |
3 |
Correct |
123 ms |
1000 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
2352 KB |
Output is correct |
7 |
Correct |
38 ms |
5052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
8468 KB |
Output is correct |
2 |
Correct |
226 ms |
9492 KB |
Output is correct |
3 |
Correct |
222 ms |
9508 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
63 ms |
212 KB |
Output is correct |
6 |
Correct |
183 ms |
1720 KB |
Output is correct |
7 |
Correct |
202 ms |
19444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
992 ms |
38704 KB |
Output is correct |
2 |
Correct |
46 ms |
5092 KB |
Output is correct |
3 |
Correct |
19 ms |
2480 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
490 ms |
38680 KB |
Output is correct |
7 |
Correct |
29 ms |
5016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5044 KB |
Output is correct |
2 |
Correct |
264 ms |
19388 KB |
Output is correct |
3 |
Correct |
15 ms |
2480 KB |
Output is correct |
4 |
Correct |
17 ms |
2480 KB |
Output is correct |
5 |
Correct |
68 ms |
324 KB |
Output is correct |
6 |
Correct |
38 ms |
5168 KB |
Output is correct |
7 |
Correct |
983 ms |
77292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1103 ms |
77284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |