#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 3e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1, inf = 2e9;
int l, q;
int big[(1 << 20)], small[(1 << 20)];
string s;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> l >> q;
cin >> s;
for(int i = 0; i < (1 << l); i++){
big[i] = (s[i] - '0'); small[i] = (s[i] - '0');
}
for(int i = 0; i < l; i++){
for(int j = 0; j < (1 << l); j++){
if(j & (1 << i))small[j] += small[j ^ (1 << i)];
else big[j] += big[j ^ (1 << i)];
}
}
string ss;
while(q--){
cin >> ss;
int zero = 0, one = 0, que = 0;
for(int i = 0; i < l; i++){
if(ss[i] == '0')zero += (1 << (l - i - 1));
else if(ss[i] == '1')one += (1 << (l - i - 1));
else que += (1 << (l - i - 1));
}
int ans = 0;
if(__builtin_popcount(que) <= 6){
int mask = one;
for(int j = que;; j = (j - 1) & que){
//cout << (mask | j) << " ";
ans += (s[mask | j] - '0');
if(j == 0)break;
}
}else if(__builtin_popcount(one) <= 6){
int mask = que;
for(int j = one;; j = (j - 1) & one){
if((__builtin_popcount(one) - __builtin_popcount(j)) & 1)ans -= small[mask | j];
else ans += small[mask | j];
if(j == 0)break;
}
}else{
int mask = one;
for(int j = zero;; j = (j - 1) & zero){
if(__builtin_popcount(j) & 1)ans -= big[mask | j];
else ans += big[mask | j];
}
}
cout << ans << "\n";
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
194 ms |
4324 KB |
Output is correct |
12 |
Correct |
184 ms |
3896 KB |
Output is correct |
13 |
Correct |
181 ms |
3208 KB |
Output is correct |
14 |
Correct |
173 ms |
3324 KB |
Output is correct |
15 |
Correct |
226 ms |
4332 KB |
Output is correct |
16 |
Correct |
202 ms |
3468 KB |
Output is correct |
17 |
Correct |
226 ms |
3532 KB |
Output is correct |
18 |
Correct |
133 ms |
5344 KB |
Output is correct |
19 |
Correct |
147 ms |
2312 KB |
Output is correct |
20 |
Correct |
205 ms |
3996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
194 ms |
4324 KB |
Output is correct |
12 |
Correct |
184 ms |
3896 KB |
Output is correct |
13 |
Correct |
181 ms |
3208 KB |
Output is correct |
14 |
Correct |
173 ms |
3324 KB |
Output is correct |
15 |
Correct |
226 ms |
4332 KB |
Output is correct |
16 |
Correct |
202 ms |
3468 KB |
Output is correct |
17 |
Correct |
226 ms |
3532 KB |
Output is correct |
18 |
Correct |
133 ms |
5344 KB |
Output is correct |
19 |
Correct |
147 ms |
2312 KB |
Output is correct |
20 |
Correct |
205 ms |
3996 KB |
Output is correct |
21 |
Correct |
269 ms |
4340 KB |
Output is correct |
22 |
Correct |
215 ms |
4464 KB |
Output is correct |
23 |
Correct |
229 ms |
3516 KB |
Output is correct |
24 |
Correct |
217 ms |
3416 KB |
Output is correct |
25 |
Correct |
194 ms |
5408 KB |
Output is correct |
26 |
Correct |
252 ms |
3864 KB |
Output is correct |
27 |
Correct |
273 ms |
3792 KB |
Output is correct |
28 |
Correct |
144 ms |
6340 KB |
Output is correct |
29 |
Correct |
171 ms |
2332 KB |
Output is correct |
30 |
Correct |
248 ms |
4504 KB |
Output is correct |
31 |
Correct |
279 ms |
4364 KB |
Output is correct |
32 |
Correct |
246 ms |
4480 KB |
Output is correct |
33 |
Correct |
188 ms |
3244 KB |
Output is correct |
34 |
Correct |
224 ms |
3328 KB |
Output is correct |
35 |
Correct |
240 ms |
3820 KB |
Output is correct |
36 |
Correct |
126 ms |
2348 KB |
Output is correct |
37 |
Correct |
236 ms |
4388 KB |
Output is correct |
38 |
Correct |
185 ms |
2292 KB |
Output is correct |
39 |
Correct |
217 ms |
3544 KB |
Output is correct |
40 |
Correct |
219 ms |
3380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
2054 ms |
9648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
194 ms |
4324 KB |
Output is correct |
12 |
Correct |
184 ms |
3896 KB |
Output is correct |
13 |
Correct |
181 ms |
3208 KB |
Output is correct |
14 |
Correct |
173 ms |
3324 KB |
Output is correct |
15 |
Correct |
226 ms |
4332 KB |
Output is correct |
16 |
Correct |
202 ms |
3468 KB |
Output is correct |
17 |
Correct |
226 ms |
3532 KB |
Output is correct |
18 |
Correct |
133 ms |
5344 KB |
Output is correct |
19 |
Correct |
147 ms |
2312 KB |
Output is correct |
20 |
Correct |
205 ms |
3996 KB |
Output is correct |
21 |
Correct |
269 ms |
4340 KB |
Output is correct |
22 |
Correct |
215 ms |
4464 KB |
Output is correct |
23 |
Correct |
229 ms |
3516 KB |
Output is correct |
24 |
Correct |
217 ms |
3416 KB |
Output is correct |
25 |
Correct |
194 ms |
5408 KB |
Output is correct |
26 |
Correct |
252 ms |
3864 KB |
Output is correct |
27 |
Correct |
273 ms |
3792 KB |
Output is correct |
28 |
Correct |
144 ms |
6340 KB |
Output is correct |
29 |
Correct |
171 ms |
2332 KB |
Output is correct |
30 |
Correct |
248 ms |
4504 KB |
Output is correct |
31 |
Correct |
279 ms |
4364 KB |
Output is correct |
32 |
Correct |
246 ms |
4480 KB |
Output is correct |
33 |
Correct |
188 ms |
3244 KB |
Output is correct |
34 |
Correct |
224 ms |
3328 KB |
Output is correct |
35 |
Correct |
240 ms |
3820 KB |
Output is correct |
36 |
Correct |
126 ms |
2348 KB |
Output is correct |
37 |
Correct |
236 ms |
4388 KB |
Output is correct |
38 |
Correct |
185 ms |
2292 KB |
Output is correct |
39 |
Correct |
217 ms |
3544 KB |
Output is correct |
40 |
Correct |
219 ms |
3380 KB |
Output is correct |
41 |
Execution timed out |
2054 ms |
9648 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |