#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> masks[2]; //eu vou ordenar o segundo bloco, e pra cada cara no 1o eu faço uma BB no 2o
ll resp = 0, m, arr[40];
int n, maxmask;
int mask_roll(int l, int r, bool div){
//calcular a mascara base
maxmask = (1LL << (r - l + 1));
for(int i = 0; i < maxmask; i++){
int soma = 0, roll = i;
for(int j = l; j <= r; j++){
if(roll%2) soma += arr[j];
roll >>= 1;
}
masks[div].push_back(soma);
}
}
ll bb(ll num){
//return +1
ll val = - 1;
int ini = 0, fim = maxmask-1;
while(ini <= fim){
int mid = (ini+fim)/2;
if(masks[1][mid] + num <= m){
val = mid;
ini = mid+1;
}
else
fim = mid-1;
}
return val+1;
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> arr[i];
int mid = n/2;
mask_roll(0, mid, 0);
mask_roll(mid+1, n-1, 1);
sort(masks[1].begin(), masks[1].end());
for(int i = 0; i < (int)masks[0].size(); i++){
resp += bb(masks[0][i]);
}
cout << resp << endl;
return 0;
}
Compilation message
bobek.cpp: In function 'int mask_roll(int, int, bool)':
bobek.cpp:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2420 KB |
Output is correct |
2 |
Correct |
145 ms |
6492 KB |
Output is correct |
3 |
Correct |
705 ms |
25024 KB |
Output is correct |
4 |
Correct |
143 ms |
6500 KB |
Output is correct |
5 |
Correct |
19 ms |
1908 KB |
Output is correct |
6 |
Correct |
9 ms |
1144 KB |
Output is correct |
7 |
Correct |
17 ms |
1908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
3460 KB |
Output is correct |
2 |
Correct |
36 ms |
2420 KB |
Output is correct |
3 |
Correct |
283 ms |
12756 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
8 ms |
1144 KB |
Output is correct |
6 |
Correct |
17 ms |
1908 KB |
Output is correct |
7 |
Correct |
17 ms |
1908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
4456 KB |
Output is correct |
2 |
Correct |
177 ms |
8668 KB |
Output is correct |
3 |
Correct |
181 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
90 ms |
8548 KB |
Output is correct |
6 |
Correct |
309 ms |
25020 KB |
Output is correct |
7 |
Correct |
95 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
16720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
2420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
336 ms |
25020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |