#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, p, t, psa[1 << 22];
ll k, a[45], ans;
vector<pair<ll, int> > v;
void dfs(int N, ll S){
if (S>k) return;
if (N==20 || N==n){
if (t==1) S=k-S;
v.pb(mp(S, t));
return;
}
dfs(N+1, S);
dfs(N+1, S+a[N]);
}
int main() {
cin >> n >> k;
fox(l,n) cin >> a[l];
if (n<=20){
t++;
} else {psa[0]--;
dfs(0, 0);
t++;
n-=20;
fox(l, 20) a[l]=a[l+20];
}
dfs(0,0);
//return 0;
sort(v.begin(), v.end());
psa[0]++;
fox(l, v.size()){
//cout << v[l].x << endl;
if (v[l].y==0) psa[l]++;
else ans+=psa[l];
psa[l+1]+=psa[l];
}
cout << ans;
return 0;
}
Compilation message
bobek.cpp: In function 'int main()':
bobek.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
bobek.cpp:56:2: note: in expansion of macro 'fox'
fox(l, v.size()){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
18400 KB |
Output is correct |
2 |
Correct |
0 ms |
18400 KB |
Output is correct |
3 |
Correct |
0 ms |
18400 KB |
Output is correct |
4 |
Correct |
0 ms |
18400 KB |
Output is correct |
5 |
Correct |
0 ms |
18400 KB |
Output is correct |
6 |
Correct |
0 ms |
18400 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21556 KB |
Output is correct |
2 |
Correct |
3 ms |
19252 KB |
Output is correct |
3 |
Correct |
6 ms |
20020 KB |
Output is correct |
4 |
Correct |
0 ms |
18400 KB |
Output is correct |
5 |
Correct |
3 ms |
20020 KB |
Output is correct |
6 |
Correct |
143 ms |
43060 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
43060 KB |
Output is correct |
2 |
Correct |
6 ms |
20020 KB |
Output is correct |
3 |
Correct |
3 ms |
20020 KB |
Output is correct |
4 |
Correct |
3 ms |
18868 KB |
Output is correct |
5 |
Correct |
33 ms |
30772 KB |
Output is correct |
6 |
Correct |
13 ms |
21556 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
67636 KB |
Output is correct |
2 |
Correct |
146 ms |
67636 KB |
Output is correct |
3 |
Correct |
329 ms |
67636 KB |
Output is correct |
4 |
Correct |
163 ms |
67636 KB |
Output is correct |
5 |
Correct |
99 ms |
43060 KB |
Output is correct |
6 |
Correct |
116 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
67636 KB |
Output is correct |
2 |
Correct |
146 ms |
43060 KB |
Output is correct |
3 |
Correct |
173 ms |
67636 KB |
Output is correct |
4 |
Correct |
0 ms |
18400 KB |
Output is correct |
5 |
Correct |
93 ms |
43060 KB |
Output is correct |
6 |
Correct |
129 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
67636 KB |
Output is correct |
2 |
Correct |
173 ms |
67636 KB |
Output is correct |
3 |
Correct |
173 ms |
67636 KB |
Output is correct |
4 |
Correct |
23 ms |
24628 KB |
Output is correct |
5 |
Correct |
106 ms |
67636 KB |
Output is correct |
6 |
Correct |
276 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
67636 KB |
Output is correct |
2 |
Correct |
149 ms |
67636 KB |
Output is correct |
3 |
Correct |
149 ms |
43060 KB |
Output is correct |
4 |
Correct |
0 ms |
18868 KB |
Output is correct |
5 |
Correct |
109 ms |
43060 KB |
Output is correct |
6 |
Correct |
226 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
67636 KB |
Output is correct |
2 |
Correct |
159 ms |
67636 KB |
Output is correct |
3 |
Correct |
149 ms |
67636 KB |
Output is correct |
4 |
Correct |
106 ms |
43060 KB |
Output is correct |
5 |
Correct |
106 ms |
67636 KB |
Output is correct |
6 |
Correct |
146 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
67636 KB |
Output is correct |
2 |
Correct |
159 ms |
43060 KB |
Output is correct |
3 |
Correct |
143 ms |
43060 KB |
Output is correct |
4 |
Correct |
319 ms |
67636 KB |
Output is correct |
5 |
Correct |
126 ms |
67636 KB |
Output is correct |
6 |
Correct |
136 ms |
67636 KB |
Output is correct |
7 |
Correct |
0 ms |
18400 KB |
Output is correct |