#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long tab[50];
vector<long long>w;
vector<long long>w2;
void calculate_values(int start,int ile,int id)
{
for(int i=0;i<(1<<ile);i++){
long long suma=0;
for(int j=0;j<ile;j++){
if((i&(1<<j))>0){
suma+=tab[start+j];
}
}
if(id==1){
w.push_back(suma);
}
else{
w2.push_back(suma);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
long long limit;
cin>>ile>>limit;
for(int i=0;i<ile;i++){
cin>>tab[i];
}
if(ile==1){
if(tab[0]<=limit){
cout<<"2";
}
else{
cout<<"1";
}
return 0;
}
calculate_values(0,ile/2,1);
calculate_values(ile/2,ile-(ile/2),2);
sort(w.begin(),w.end());
sort(w2.begin(),w2.end());
long long war=0;
long long index=-1;
for(int i=(int)w.size()-1;i>=0;i--){
while(index+1<(int)w2.size()&&w2[index+1]+w[i]<=limit){
index++;
}
war+=(index+1);
}
cout<<war;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
2140 KB |
Output is correct |
2 |
Correct |
70 ms |
5576 KB |
Output is correct |
3 |
Correct |
295 ms |
21940 KB |
Output is correct |
4 |
Correct |
69 ms |
5576 KB |
Output is correct |
5 |
Correct |
12 ms |
1756 KB |
Output is correct |
6 |
Correct |
8 ms |
1112 KB |
Output is correct |
7 |
Correct |
16 ms |
1752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
3032 KB |
Output is correct |
2 |
Correct |
26 ms |
2144 KB |
Output is correct |
3 |
Correct |
123 ms |
12088 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
6 ms |
988 KB |
Output is correct |
6 |
Correct |
16 ms |
1500 KB |
Output is correct |
7 |
Correct |
16 ms |
1752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
3676 KB |
Output is correct |
2 |
Correct |
105 ms |
7788 KB |
Output is correct |
3 |
Correct |
108 ms |
7452 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
72 ms |
7768 KB |
Output is correct |
6 |
Correct |
261 ms |
22160 KB |
Output is correct |
7 |
Correct |
104 ms |
7500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
14724 KB |
Output is correct |
2 |
Correct |
24 ms |
2144 KB |
Output is correct |
3 |
Correct |
8 ms |
1112 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1032 KB |
Output is correct |
6 |
Correct |
217 ms |
13920 KB |
Output is correct |
7 |
Correct |
16 ms |
1500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2144 KB |
Output is correct |
2 |
Correct |
70 ms |
5580 KB |
Output is correct |
3 |
Correct |
8 ms |
988 KB |
Output is correct |
4 |
Correct |
8 ms |
1116 KB |
Output is correct |
5 |
Correct |
81 ms |
8180 KB |
Output is correct |
6 |
Correct |
24 ms |
2144 KB |
Output is correct |
7 |
Correct |
285 ms |
21164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
288 ms |
21684 KB |
Output is correct |
2 |
Correct |
25 ms |
2124 KB |
Output is correct |
3 |
Correct |
8 ms |
1116 KB |
Output is correct |
4 |
Correct |
296 ms |
22908 KB |
Output is correct |
5 |
Correct |
102 ms |
12232 KB |
Output is correct |
6 |
Correct |
17 ms |
1752 KB |
Output is correct |
7 |
Correct |
33 ms |
3032 KB |
Output is correct |