#include <iostream>
#include <climits>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>
#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int64_t __i = 0; __i<(int64_t)a.size();__i++){cin>>a[__i];}
// jimjam
template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
if (c.size() == 0) {os << "{}"; return os;}
os << "{" << c[0];
for (int64_t i = 1; i < (int64_t)c.size(); i++) {os <<", "<<c[i];}
os << "}";
return os;
}
const int64_t inf = 2e9;
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t n, m; cin >> n >> m;
vector<int64_t> a(n);
readVec(a);
if (n==1) {
cout << 1+(a[0]<=m) << '\n';
return 0;
}
int64_t mid = n/2;
vector<int64_t> leftSum;
for (int64_t mask = 0; mask < 1<<(mid+1); mask++) {
int64_t su=0;
for (int64_t i = 0; i <= mid; i++) {
if (mask & (1<<i)) {
su += a[i];
}
}
leftSum.push_back(su);
}
int64_t rL = mid+1;
int64_t rSize = n-rL;
vector<int64_t> rightSum;
for (int64_t mask = 0; mask < 1<<rSize; mask++) {
int64_t su=0;
for (int64_t i = mid+1; i < n; i++) {
if (mask & (1<<(i-(mid+1)))) {
su += a[i];
}
}
rightSum.push_back(su);
}
int64_t ans=0;
sort(rightSum.begin(),rightSum.end());
for (int64_t i: leftSum) {
auto iter = lower_bound(rightSum.begin(),rightSum.end(), m-i+1);
ans += distance(rightSum.begin(),iter);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
376 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
2536 KB |
Output is correct |
2 |
Correct |
140 ms |
6492 KB |
Output is correct |
3 |
Correct |
687 ms |
25060 KB |
Output is correct |
4 |
Correct |
136 ms |
6492 KB |
Output is correct |
5 |
Correct |
19 ms |
1896 KB |
Output is correct |
6 |
Correct |
8 ms |
1132 KB |
Output is correct |
7 |
Correct |
17 ms |
1896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
3428 KB |
Output is correct |
2 |
Correct |
34 ms |
2408 KB |
Output is correct |
3 |
Correct |
280 ms |
12624 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
8 ms |
1132 KB |
Output is correct |
6 |
Correct |
16 ms |
1896 KB |
Output is correct |
7 |
Correct |
17 ms |
1896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
4452 KB |
Output is correct |
2 |
Correct |
168 ms |
8540 KB |
Output is correct |
3 |
Correct |
175 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
86 ms |
8540 KB |
Output is correct |
6 |
Correct |
294 ms |
25020 KB |
Output is correct |
7 |
Correct |
103 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
362 ms |
16784 KB |
Output is correct |
2 |
Correct |
32 ms |
2408 KB |
Output is correct |
3 |
Correct |
14 ms |
1132 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
9 ms |
1132 KB |
Output is correct |
6 |
Correct |
194 ms |
16720 KB |
Output is correct |
7 |
Correct |
17 ms |
1896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2408 KB |
Output is correct |
2 |
Correct |
130 ms |
6492 KB |
Output is correct |
3 |
Correct |
12 ms |
1132 KB |
Output is correct |
4 |
Correct |
14 ms |
1132 KB |
Output is correct |
5 |
Correct |
98 ms |
8540 KB |
Output is correct |
6 |
Correct |
22 ms |
2408 KB |
Output is correct |
7 |
Correct |
330 ms |
25020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
25148 KB |
Output is correct |
2 |
Correct |
36 ms |
2408 KB |
Output is correct |
3 |
Correct |
14 ms |
1132 KB |
Output is correct |
4 |
Correct |
676 ms |
25020 KB |
Output is correct |
5 |
Correct |
158 ms |
12752 KB |
Output is correct |
6 |
Correct |
16 ms |
1896 KB |
Output is correct |
7 |
Correct |
35 ms |
3428 KB |
Output is correct |