#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
int l, q; cin >> l >> q;
string s; cin >> s;
int sum[MASK(l)];
memset(sum, 0, sizeof sum);
for(int i= 0; i<MASK(l); ++i){
sum[i] = s[i] - '0';
}
for(int j = 0; j < l; ++j) for(int i = 0; i<MASK(l); ++i) if (GETBIT(i, j)){
sum[i] += sum[i - MASK(j)];
}
while(q--){
string _s; cin >> _s;
reverse(ALL(_s));
int mask1 = 0, mask2 = 0;
for(int i = 0; i<l; ++i) {
if (_s[i] == '1') mask1 += MASK(i);
else if (_s[i] == '?') mask2 += MASK(i);
}
if (pop_cnt(mask2) <= 10){
int ans = 0;
for(int mask = mask2; mask >= 0; mask = (mask - 1) & mask2){
ans += s[mask + mask1] - '0';
if (mask == 0) break;
}
cout << ans << "\n";
}
else{
int ans = 0;
int cur_pop = pop_cnt(mask1);
for(int mask = mask1; mask >= 0; mask = (mask - 1) & mask1){
if ((pop_cnt(mask) & 1) == (cur_pop & 1)) ans += sum[mask + mask2];
else ans -= sum[mask + mask2];
if (mask == 0) break;
}
cout << ans << "\n";
}
}
cerr << "Time elapsed: " << clock() - start << " ms\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
170 ms |
15060 KB |
Output is correct |
12 |
Correct |
172 ms |
14672 KB |
Output is correct |
13 |
Correct |
145 ms |
13908 KB |
Output is correct |
14 |
Correct |
157 ms |
14044 KB |
Output is correct |
15 |
Correct |
186 ms |
15184 KB |
Output is correct |
16 |
Correct |
153 ms |
14240 KB |
Output is correct |
17 |
Correct |
162 ms |
14336 KB |
Output is correct |
18 |
Correct |
1116 ms |
16216 KB |
Output is correct |
19 |
Correct |
141 ms |
13140 KB |
Output is correct |
20 |
Correct |
214 ms |
14724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
170 ms |
15060 KB |
Output is correct |
12 |
Correct |
172 ms |
14672 KB |
Output is correct |
13 |
Correct |
145 ms |
13908 KB |
Output is correct |
14 |
Correct |
157 ms |
14044 KB |
Output is correct |
15 |
Correct |
186 ms |
15184 KB |
Output is correct |
16 |
Correct |
153 ms |
14240 KB |
Output is correct |
17 |
Correct |
162 ms |
14336 KB |
Output is correct |
18 |
Correct |
1116 ms |
16216 KB |
Output is correct |
19 |
Correct |
141 ms |
13140 KB |
Output is correct |
20 |
Correct |
214 ms |
14724 KB |
Output is correct |
21 |
Correct |
302 ms |
18208 KB |
Output is correct |
22 |
Correct |
312 ms |
18296 KB |
Output is correct |
23 |
Correct |
170 ms |
17292 KB |
Output is correct |
24 |
Correct |
158 ms |
17204 KB |
Output is correct |
25 |
Correct |
397 ms |
19028 KB |
Output is correct |
26 |
Correct |
204 ms |
17492 KB |
Output is correct |
27 |
Correct |
208 ms |
17472 KB |
Output is correct |
28 |
Correct |
130 ms |
19988 KB |
Output is correct |
29 |
Correct |
172 ms |
16208 KB |
Output is correct |
30 |
Correct |
364 ms |
18256 KB |
Output is correct |
31 |
Correct |
205 ms |
18004 KB |
Output is correct |
32 |
Correct |
175 ms |
17976 KB |
Output is correct |
33 |
Correct |
161 ms |
17064 KB |
Output is correct |
34 |
Correct |
171 ms |
17016 KB |
Output is correct |
35 |
Correct |
187 ms |
17484 KB |
Output is correct |
36 |
Correct |
108 ms |
16208 KB |
Output is correct |
37 |
Correct |
174 ms |
18000 KB |
Output is correct |
38 |
Correct |
170 ms |
16212 KB |
Output is correct |
39 |
Correct |
181 ms |
17232 KB |
Output is correct |
40 |
Correct |
180 ms |
17224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
100 ms |
7900 KB |
Output is correct |
12 |
Correct |
56 ms |
7852 KB |
Output is correct |
13 |
Correct |
37 ms |
7752 KB |
Output is correct |
14 |
Correct |
45 ms |
7928 KB |
Output is correct |
15 |
Correct |
36 ms |
7924 KB |
Output is correct |
16 |
Correct |
51 ms |
7928 KB |
Output is correct |
17 |
Correct |
49 ms |
7920 KB |
Output is correct |
18 |
Correct |
32 ms |
7932 KB |
Output is correct |
19 |
Correct |
34 ms |
7664 KB |
Output is correct |
20 |
Correct |
73 ms |
7920 KB |
Output is correct |
21 |
Correct |
98 ms |
7924 KB |
Output is correct |
22 |
Correct |
50 ms |
7924 KB |
Output is correct |
23 |
Correct |
33 ms |
7752 KB |
Output is correct |
24 |
Correct |
42 ms |
7920 KB |
Output is correct |
25 |
Correct |
50 ms |
7920 KB |
Output is correct |
26 |
Correct |
31 ms |
7668 KB |
Output is correct |
27 |
Correct |
94 ms |
7964 KB |
Output is correct |
28 |
Correct |
36 ms |
7752 KB |
Output is correct |
29 |
Correct |
40 ms |
7924 KB |
Output is correct |
30 |
Correct |
40 ms |
7808 KB |
Output is correct |
31 |
Correct |
34 ms |
7920 KB |
Output is correct |
32 |
Correct |
49 ms |
7748 KB |
Output is correct |
33 |
Correct |
55 ms |
7900 KB |
Output is correct |
34 |
Correct |
30 ms |
7664 KB |
Output is correct |
35 |
Correct |
52 ms |
7924 KB |
Output is correct |
36 |
Correct |
50 ms |
7748 KB |
Output is correct |
37 |
Correct |
49 ms |
7748 KB |
Output is correct |
38 |
Correct |
51 ms |
7920 KB |
Output is correct |
39 |
Correct |
57 ms |
7748 KB |
Output is correct |
40 |
Correct |
50 ms |
7924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
170 ms |
15060 KB |
Output is correct |
12 |
Correct |
172 ms |
14672 KB |
Output is correct |
13 |
Correct |
145 ms |
13908 KB |
Output is correct |
14 |
Correct |
157 ms |
14044 KB |
Output is correct |
15 |
Correct |
186 ms |
15184 KB |
Output is correct |
16 |
Correct |
153 ms |
14240 KB |
Output is correct |
17 |
Correct |
162 ms |
14336 KB |
Output is correct |
18 |
Correct |
1116 ms |
16216 KB |
Output is correct |
19 |
Correct |
141 ms |
13140 KB |
Output is correct |
20 |
Correct |
214 ms |
14724 KB |
Output is correct |
21 |
Correct |
302 ms |
18208 KB |
Output is correct |
22 |
Correct |
312 ms |
18296 KB |
Output is correct |
23 |
Correct |
170 ms |
17292 KB |
Output is correct |
24 |
Correct |
158 ms |
17204 KB |
Output is correct |
25 |
Correct |
397 ms |
19028 KB |
Output is correct |
26 |
Correct |
204 ms |
17492 KB |
Output is correct |
27 |
Correct |
208 ms |
17472 KB |
Output is correct |
28 |
Correct |
130 ms |
19988 KB |
Output is correct |
29 |
Correct |
172 ms |
16208 KB |
Output is correct |
30 |
Correct |
364 ms |
18256 KB |
Output is correct |
31 |
Correct |
205 ms |
18004 KB |
Output is correct |
32 |
Correct |
175 ms |
17976 KB |
Output is correct |
33 |
Correct |
161 ms |
17064 KB |
Output is correct |
34 |
Correct |
171 ms |
17016 KB |
Output is correct |
35 |
Correct |
187 ms |
17484 KB |
Output is correct |
36 |
Correct |
108 ms |
16208 KB |
Output is correct |
37 |
Correct |
174 ms |
18000 KB |
Output is correct |
38 |
Correct |
170 ms |
16212 KB |
Output is correct |
39 |
Correct |
181 ms |
17232 KB |
Output is correct |
40 |
Correct |
180 ms |
17224 KB |
Output is correct |
41 |
Correct |
100 ms |
7900 KB |
Output is correct |
42 |
Correct |
56 ms |
7852 KB |
Output is correct |
43 |
Correct |
37 ms |
7752 KB |
Output is correct |
44 |
Correct |
45 ms |
7928 KB |
Output is correct |
45 |
Correct |
36 ms |
7924 KB |
Output is correct |
46 |
Correct |
51 ms |
7928 KB |
Output is correct |
47 |
Correct |
49 ms |
7920 KB |
Output is correct |
48 |
Correct |
32 ms |
7932 KB |
Output is correct |
49 |
Correct |
34 ms |
7664 KB |
Output is correct |
50 |
Correct |
73 ms |
7920 KB |
Output is correct |
51 |
Correct |
98 ms |
7924 KB |
Output is correct |
52 |
Correct |
50 ms |
7924 KB |
Output is correct |
53 |
Correct |
33 ms |
7752 KB |
Output is correct |
54 |
Correct |
42 ms |
7920 KB |
Output is correct |
55 |
Correct |
50 ms |
7920 KB |
Output is correct |
56 |
Correct |
31 ms |
7668 KB |
Output is correct |
57 |
Correct |
94 ms |
7964 KB |
Output is correct |
58 |
Correct |
36 ms |
7752 KB |
Output is correct |
59 |
Correct |
40 ms |
7924 KB |
Output is correct |
60 |
Correct |
40 ms |
7808 KB |
Output is correct |
61 |
Correct |
34 ms |
7920 KB |
Output is correct |
62 |
Correct |
49 ms |
7748 KB |
Output is correct |
63 |
Correct |
55 ms |
7900 KB |
Output is correct |
64 |
Correct |
30 ms |
7664 KB |
Output is correct |
65 |
Correct |
52 ms |
7924 KB |
Output is correct |
66 |
Correct |
50 ms |
7748 KB |
Output is correct |
67 |
Correct |
49 ms |
7748 KB |
Output is correct |
68 |
Correct |
51 ms |
7920 KB |
Output is correct |
69 |
Correct |
57 ms |
7748 KB |
Output is correct |
70 |
Correct |
50 ms |
7924 KB |
Output is correct |
71 |
Correct |
1419 ms |
32244 KB |
Output is correct |
72 |
Correct |
591 ms |
32300 KB |
Output is correct |
73 |
Correct |
328 ms |
30760 KB |
Output is correct |
74 |
Correct |
448 ms |
31392 KB |
Output is correct |
75 |
Correct |
296 ms |
33092 KB |
Output is correct |
76 |
Correct |
572 ms |
31484 KB |
Output is correct |
77 |
Correct |
524 ms |
31316 KB |
Output is correct |
78 |
Correct |
186 ms |
35292 KB |
Output is correct |
79 |
Correct |
251 ms |
29168 KB |
Output is correct |
80 |
Correct |
1034 ms |
32324 KB |
Output is correct |
81 |
Correct |
1494 ms |
32076 KB |
Output is correct |
82 |
Correct |
433 ms |
31196 KB |
Output is correct |
83 |
Correct |
261 ms |
30272 KB |
Output is correct |
84 |
Correct |
336 ms |
31304 KB |
Output is correct |
85 |
Correct |
518 ms |
31476 KB |
Output is correct |
86 |
Correct |
160 ms |
29168 KB |
Output is correct |
87 |
Correct |
1290 ms |
32308 KB |
Output is correct |
88 |
Correct |
248 ms |
29204 KB |
Output is correct |
89 |
Correct |
323 ms |
30968 KB |
Output is correct |
90 |
Correct |
347 ms |
31216 KB |
Output is correct |
91 |
Correct |
223 ms |
30276 KB |
Output is correct |
92 |
Correct |
546 ms |
31540 KB |
Output is correct |
93 |
Correct |
512 ms |
31300 KB |
Output is correct |
94 |
Correct |
175 ms |
29172 KB |
Output is correct |
95 |
Correct |
569 ms |
31744 KB |
Output is correct |
96 |
Correct |
551 ms |
31220 KB |
Output is correct |
97 |
Correct |
560 ms |
31220 KB |
Output is correct |
98 |
Correct |
530 ms |
31216 KB |
Output is correct |
99 |
Correct |
555 ms |
31196 KB |
Output is correct |
100 |
Correct |
593 ms |
31284 KB |
Output is correct |