//I wanna live before i die
#include<bits/stdc++.h>
using namespace std;
const long long maxn = 500 + 5, inf = 1e16 + 69, V = 5, delta = 998244353;
long long n, m;
map<long long, long long> w;
vector<pair<long long, long long> > part;
vector<long long> v;
long long dp[maxn];
long long find_first(long long mask){
for(long long i = 0;; i++)
if((1 << i) & mask)
return i;
}
void first_part(long long sz){
for(long long mask = 1; mask < (1 << sz); mask++){
long long u = find_first(mask);
if(__builtin_popcount(mask) == 1)
dp[mask] = v[u];
else
dp[mask] = dp[mask - (mask & -mask)] + v[u];
w[dp[mask]]++;
}
}
long long make_part_1(){
part.push_back(make_pair(0, 1));
long long A = 1;
for(auto e : w){
long long f = e.first;
long long s = part[part.size() - 1].second + e.second;
part.push_back(make_pair(f, s));
A = s;
}
return A;
}
long long find_amount(long long A){
if(A < 0)
return 0;
pair<long long, long long> p = {A, inf};
long long e = upper_bound(part.begin(), part.end(), p) - part.begin();
return part[e - 1].second;
}
long long second_part(long long sz){
memset(dp, 0, sizeof dp);
long long Ans = 0;
for(long long mask = 1; mask < (1 << (n - sz)); mask++){
long long u = find_first(mask) + sz;
if(__builtin_popcount(mask) == 1)
dp[mask] = v[u];
else
dp[mask] = dp[mask - (mask & -mask)] + v[u];
Ans += find_amount(m - dp[mask] - 1);
}
return Ans;
}
void input(){
cin >> n >> m;
for(long long i = 0; i < n; i++){
long long tmp;
cin >> tmp;
v.push_back(tmp);
}
}
void calc(){
first_part(n / 2);
cout << (make_part_1() + second_part(n / 2)) << endl;
}
int main(){
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
input();
calc();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |