#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,ll> frq;
for(int mask=0;mask<(1<<n/2);mask++){
ll sum = 0;
for(int i=0;i<n/2;i++){
if((1<<i)&mask){
sum += v[i];
}
}
frq[sum] ++;
}
ll prev = 0;
vector<ll> tmp;
for(auto &i : frq){
i.second += prev;
tmp.push_back(i.first);
prev = i.second;
}
int rem = n-n/2;
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/2+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);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
220 KB |
Output is correct |
5 |
Correct |
1 ms |
216 KB |
Output is correct |
6 |
Correct |
0 ms |
216 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
340 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
1172 KB |
Output is correct |
2 |
Correct |
325 ms |
13020 KB |
Output is correct |
3 |
Execution timed out |
1093 ms |
33200 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
1868 KB |
Output is correct |
2 |
Correct |
70 ms |
4108 KB |
Output is correct |
3 |
Correct |
194 ms |
1040 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
21 ms |
2348 KB |
Output is correct |
7 |
Correct |
26 ms |
4928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
8092 KB |
Output is correct |
2 |
Correct |
415 ms |
9160 KB |
Output is correct |
3 |
Correct |
313 ms |
9256 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
62 ms |
300 KB |
Output is correct |
6 |
Correct |
259 ms |
1744 KB |
Output is correct |
7 |
Correct |
188 ms |
18856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
37340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
4968 KB |
Output is correct |
2 |
Correct |
398 ms |
18900 KB |
Output is correct |
3 |
Correct |
17 ms |
2748 KB |
Output is correct |
4 |
Correct |
19 ms |
2712 KB |
Output is correct |
5 |
Correct |
75 ms |
212 KB |
Output is correct |
6 |
Correct |
34 ms |
5044 KB |
Output is correct |
7 |
Correct |
991 ms |
74288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1098 ms |
74236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |