/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
#define int long long
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0 //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);}
void debug(){eol;} template<typename Arg,typename... Args> void debug(Arg arg,Args... args){put (arg)<<" ";debug(args...);}
int getInt(){int a; get a; return a;}
//code goes here
void run() {
int n, m;
read(n, m);
int a[n];
rep(i, 0, n)
get a[i];
int v = n / 2;
vint left, right;
for (int mask = 0; mask < (1 << v); mask++) {
int price = 0;
rep(i, 0, v)
if (mask & (1 << i))
price += a[i];
left.pb(price);
}
for (int mask = 0; mask < (1 << (n - v)); mask++) {
int price = 0;
rep(i, v, n)
if (mask & (1 << (i - v)))
price += a[i];
right.pb(price);
}
sort(left.begin(), left.end());
sort(right.begin(), right.end());
int ans = 0;
rep(i, 0, sz(left)) {
int may = m - left[i];
int ind = upper_bound(right.begin(), right.end(), may) - right.begin();
ans += ind;
}
put ans;
}
int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
616 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
660 KB |
Output is correct |
5 |
Correct |
2 ms |
772 KB |
Output is correct |
6 |
Correct |
2 ms |
912 KB |
Output is correct |
7 |
Correct |
2 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
912 KB |
Output is correct |
2 |
Correct |
3 ms |
912 KB |
Output is correct |
3 |
Correct |
3 ms |
912 KB |
Output is correct |
4 |
Correct |
2 ms |
912 KB |
Output is correct |
5 |
Correct |
3 ms |
912 KB |
Output is correct |
6 |
Correct |
3 ms |
912 KB |
Output is correct |
7 |
Correct |
2 ms |
912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
912 KB |
Output is correct |
2 |
Correct |
3 ms |
912 KB |
Output is correct |
3 |
Correct |
3 ms |
912 KB |
Output is correct |
4 |
Correct |
2 ms |
916 KB |
Output is correct |
5 |
Correct |
4 ms |
1040 KB |
Output is correct |
6 |
Correct |
3 ms |
1040 KB |
Output is correct |
7 |
Correct |
3 ms |
1040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2592 KB |
Output is correct |
2 |
Correct |
116 ms |
6040 KB |
Output is correct |
3 |
Correct |
519 ms |
21456 KB |
Output is correct |
4 |
Correct |
119 ms |
21456 KB |
Output is correct |
5 |
Correct |
22 ms |
21456 KB |
Output is correct |
6 |
Correct |
15 ms |
21456 KB |
Output is correct |
7 |
Correct |
26 ms |
21456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
21456 KB |
Output is correct |
2 |
Correct |
40 ms |
21456 KB |
Output is correct |
3 |
Correct |
216 ms |
21456 KB |
Output is correct |
4 |
Correct |
2 ms |
21456 KB |
Output is correct |
5 |
Correct |
12 ms |
21456 KB |
Output is correct |
6 |
Correct |
29 ms |
21456 KB |
Output is correct |
7 |
Correct |
27 ms |
21456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
21456 KB |
Output is correct |
2 |
Correct |
182 ms |
21456 KB |
Output is correct |
3 |
Correct |
166 ms |
21456 KB |
Output is correct |
4 |
Correct |
3 ms |
21456 KB |
Output is correct |
5 |
Correct |
133 ms |
21456 KB |
Output is correct |
6 |
Correct |
501 ms |
21472 KB |
Output is correct |
7 |
Correct |
168 ms |
21472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
21472 KB |
Output is correct |
2 |
Correct |
40 ms |
21472 KB |
Output is correct |
3 |
Correct |
16 ms |
21472 KB |
Output is correct |
4 |
Correct |
3 ms |
21472 KB |
Output is correct |
5 |
Correct |
12 ms |
21472 KB |
Output is correct |
6 |
Correct |
368 ms |
21472 KB |
Output is correct |
7 |
Correct |
25 ms |
21472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
21472 KB |
Output is correct |
2 |
Correct |
114 ms |
21472 KB |
Output is correct |
3 |
Correct |
15 ms |
21472 KB |
Output is correct |
4 |
Correct |
17 ms |
21472 KB |
Output is correct |
5 |
Correct |
150 ms |
21472 KB |
Output is correct |
6 |
Correct |
44 ms |
21472 KB |
Output is correct |
7 |
Correct |
464 ms |
21712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
486 ms |
21712 KB |
Output is correct |
2 |
Correct |
49 ms |
21712 KB |
Output is correct |
3 |
Correct |
16 ms |
21712 KB |
Output is correct |
4 |
Correct |
548 ms |
21712 KB |
Output is correct |
5 |
Correct |
170 ms |
21712 KB |
Output is correct |
6 |
Correct |
29 ms |
21712 KB |
Output is correct |
7 |
Correct |
54 ms |
21712 KB |
Output is correct |