#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;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 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 |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
980 KB |
Output is correct |
2 |
Correct |
134 ms |
10000 KB |
Output is correct |
3 |
Correct |
697 ms |
27892 KB |
Output is correct |
4 |
Correct |
134 ms |
12080 KB |
Output is correct |
5 |
Correct |
10 ms |
320 KB |
Output is correct |
6 |
Correct |
5 ms |
712 KB |
Output is correct |
7 |
Correct |
23 ms |
4068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1368 KB |
Output is correct |
2 |
Correct |
49 ms |
3468 KB |
Output is correct |
3 |
Correct |
101 ms |
848 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
14 ms |
1968 KB |
Output is correct |
7 |
Correct |
21 ms |
4048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
6816 KB |
Output is correct |
2 |
Correct |
154 ms |
7548 KB |
Output is correct |
3 |
Correct |
167 ms |
7572 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
58 ms |
212 KB |
Output is correct |
6 |
Correct |
148 ms |
1356 KB |
Output is correct |
7 |
Correct |
147 ms |
15316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
929 ms |
30492 KB |
Output is correct |
2 |
Correct |
40 ms |
4068 KB |
Output is correct |
3 |
Correct |
15 ms |
1968 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
212 KB |
Output is correct |
6 |
Correct |
429 ms |
30436 KB |
Output is correct |
7 |
Correct |
25 ms |
4068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
4060 KB |
Output is correct |
2 |
Correct |
209 ms |
15340 KB |
Output is correct |
3 |
Correct |
16 ms |
1968 KB |
Output is correct |
4 |
Correct |
15 ms |
2084 KB |
Output is correct |
5 |
Correct |
69 ms |
324 KB |
Output is correct |
6 |
Correct |
33 ms |
4068 KB |
Output is correct |
7 |
Correct |
803 ms |
60792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
60852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |