#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define ll int
#define ll long long
#define rep(i,x,y) for(int i=x;i<=(y);i++)
#define drep(i,x,y) for(int i=x;i>=(y);i--)
#define pb push_back
#define lb long double
using namespace std;
inline ll in(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') (ch=='-'?f=-1:1),ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); return x*f; }
int n;
ll m,w[45],cnt,ans,p[(1<<24)];
int main(){
n=in(); m=in();
rep(i,1,n) w[i]=in();
sort(w+1,w+1+n);
if(n==1){
pf("%lld\n",(m>=w[1]?1:0));
return 0;
}
int s=n/2-1;
rep(i,0,(1<<s)-1){
ll v=0;
rep(j,0,s-1){
if((i>>j)&1) v+=w[j+1];
if(v>m) break;
}
if(v>m) continue;
p[++cnt]=v;
}
sort(p+1,p+1+cnt);
s=n-s;
rep(i,0,(1<<s)-1){
ll v=0;
rep(j,0,s-1){
if((i>>j)&1) v+=w[j+n/2];
if(v>m) break;
}
if(v>m) continue;
ll d=upper_bound(p+1,p+1+cnt,m-v)-p-1;
// cout<<d<<' '<<p[d]<<" "<<v<<"\n";
ans+=d;
}
pf("%lld\n",ans);
return 0;
}
Compilation message
bobek.cpp:5: warning: "ll" redefined
5 | #define ll long long
|
bobek.cpp:4: note: this is the location of the previous definition
4 | #define ll int
|
bobek.cpp: In function 'int main()':
bobek.cpp:20:10: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
20 | pf("%lld\n",(m>=w[1]?1:0));
| ~~~^ ~~~~~~~~~~~~~
| | |
| | int
| long long int
| %d
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
280 KB |
Output is correct |
3 |
Correct |
0 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 |
308 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 |
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 |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
468 KB |
Output is correct |
2 |
Correct |
86 ms |
1316 KB |
Output is correct |
3 |
Correct |
397 ms |
4388 KB |
Output is correct |
4 |
Correct |
87 ms |
1236 KB |
Output is correct |
5 |
Correct |
15 ms |
564 KB |
Output is correct |
6 |
Correct |
7 ms |
432 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
800 KB |
Output is correct |
2 |
Correct |
31 ms |
564 KB |
Output is correct |
3 |
Correct |
176 ms |
2344 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
844 KB |
Output is correct |
2 |
Correct |
149 ms |
1312 KB |
Output is correct |
3 |
Correct |
147 ms |
1312 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
99 ms |
1328 KB |
Output is correct |
6 |
Correct |
255 ms |
4388 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
2332 KB |
Output is correct |
2 |
Correct |
29 ms |
468 KB |
Output is correct |
3 |
Correct |
9 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
436 KB |
Output is correct |
6 |
Correct |
225 ms |
2344 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
468 KB |
Output is correct |
2 |
Correct |
77 ms |
1228 KB |
Output is correct |
3 |
Correct |
7 ms |
436 KB |
Output is correct |
4 |
Correct |
8 ms |
308 KB |
Output is correct |
5 |
Correct |
117 ms |
1236 KB |
Output is correct |
6 |
Correct |
26 ms |
564 KB |
Output is correct |
7 |
Correct |
6 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
4344 KB |
Output is correct |
2 |
Correct |
33 ms |
560 KB |
Output is correct |
3 |
Correct |
11 ms |
340 KB |
Output is correct |
4 |
Correct |
397 ms |
4392 KB |
Output is correct |
5 |
Correct |
130 ms |
2260 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |