#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
ll pr[41];
vector<long long> a={0},b={0};
void solvea(ll curr,ll pos,ll end) {
if (curr == m) {
return;
}
for (int i=pos+1;i<end;i++) {
if (curr+pr[i] <= m) {
a.push_back(curr+pr[i]);
solvea(curr+pr[i],i,end);
} else {
return;
}
}
return;
}
void solveb(ll curr,ll pos,ll end) {
if (curr == m) {
return;
}
for (int i=pos+1;i<end;i++) {
if (curr+pr[i] <= m) {
b.push_back(curr+pr[i]);
solveb(curr+pr[i],i,end);
} else {
return;
}
}
return;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> m;
for (int i=0;i<n;i++) {
cin >> pr[i];
if (pr[i] > m) {
i--;
n--;
}
}
sort(pr,pr+n);
solvea(0,-1,n/2);
solveb(0,n/2-1,n);
sort(b.begin(),b.end());
ll cnt=0;
n = a.size();
for (int i=0;i<n;i++) {
cnt+=upper_bound(b.begin(),b.end(),m-a[i])-b.begin();
}
cout << cnt;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
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 |
0 ms |
344 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 |
1 ms |
460 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 |
456 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 |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2144 KB |
Output is correct |
2 |
Correct |
49 ms |
5588 KB |
Output is correct |
3 |
Correct |
233 ms |
22476 KB |
Output is correct |
4 |
Correct |
49 ms |
5584 KB |
Output is correct |
5 |
Correct |
5 ms |
1752 KB |
Output is correct |
6 |
Correct |
3 ms |
988 KB |
Output is correct |
7 |
Correct |
0 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3032 KB |
Output is correct |
2 |
Correct |
17 ms |
2144 KB |
Output is correct |
3 |
Correct |
93 ms |
11472 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
988 KB |
Output is correct |
6 |
Correct |
6 ms |
1500 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
3676 KB |
Output is correct |
2 |
Correct |
71 ms |
7508 KB |
Output is correct |
3 |
Correct |
70 ms |
7508 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
28 ms |
8024 KB |
Output is correct |
6 |
Correct |
102 ms |
22732 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
13908 KB |
Output is correct |
2 |
Correct |
16 ms |
1992 KB |
Output is correct |
3 |
Correct |
5 ms |
992 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
992 KB |
Output is correct |
6 |
Correct |
97 ms |
14420 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2144 KB |
Output is correct |
2 |
Correct |
49 ms |
5588 KB |
Output is correct |
3 |
Correct |
5 ms |
992 KB |
Output is correct |
4 |
Correct |
5 ms |
992 KB |
Output is correct |
5 |
Correct |
27 ms |
6848 KB |
Output is correct |
6 |
Correct |
11 ms |
2144 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
21708 KB |
Output is correct |
2 |
Correct |
14 ms |
2144 KB |
Output is correct |
3 |
Correct |
5 ms |
1116 KB |
Output is correct |
4 |
Correct |
214 ms |
20940 KB |
Output is correct |
5 |
Correct |
39 ms |
12492 KB |
Output is correct |
6 |
Correct |
6 ms |
1756 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |