#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
typedef pair<int,pii> P;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int pw[22] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152};
int main()
{
owo
int l,q;
cin>>l>>q;
vector<int>sub(pw[(l+1)]),sup(pw[(l+1)]),cnt(pw[l+1]);
for(int i=0;i<(1<<(l+1));i++)cnt[i] = __builtin_popcount(i);
string snek;
for(int i=0;i<pw[l];i++){
char c;cin>>c;
sub[i]+=c-'0';
sup[i]+=c-'0';
snek+=c;
}
for(int i=0;i<l;i++){
for(int j=0;j<pw[l];j++){
if(j&pw[i])sub[j]+=sub[j^pw[i]];
else sup[j]+=sup[j^pw[i]];
}
}
while(q--){
int A=0,B=0,C=0;
vector<int>a,b,c;
string s;cin>>s;
int ans = 0;
for(int i=0;i<l;i++){
if(s[i] == '?'){c.pb(l-i-1);C+=pw[l-i-1];}
else if(s[i] == '0'){a.pb(l-i-1);A+=pw[l-i-1];}
else {b.pb(l-i-1);B+=pw[l-i-1];}
}
if(sz(c) <= 6){
for(int i=C;i!=0;i=(i-1)&C){
ans+=snek[B|i]-'0';
}
ans+=snek[B]-'0';
}
else if(sz(a) <= 6){
for(int i=A;i!=0;i=(i-1)&A){
if(cnt[i]&1)ans-=sup[i|B];
else ans+=sup[i|B];
}
ans+=sup[B];
}else{
for(int i=B;i!=0;i=(i-1)&B){
if((cnt[B]-cnt[i])&1)ans-=sub[C|i];
else ans+=sub[C|i];
}
if(cnt[B]&1)ans-=sub[C];
else ans+=sub[C];
}
cout<<ans<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
592 ms |
4972 KB |
Output is correct |
12 |
Correct |
630 ms |
4588 KB |
Output is correct |
13 |
Correct |
585 ms |
3820 KB |
Output is correct |
14 |
Correct |
587 ms |
4076 KB |
Output is correct |
15 |
Correct |
638 ms |
4972 KB |
Output is correct |
16 |
Correct |
619 ms |
4076 KB |
Output is correct |
17 |
Correct |
635 ms |
4340 KB |
Output is correct |
18 |
Correct |
381 ms |
5868 KB |
Output is correct |
19 |
Correct |
566 ms |
2924 KB |
Output is correct |
20 |
Correct |
579 ms |
4588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
592 ms |
4972 KB |
Output is correct |
12 |
Correct |
630 ms |
4588 KB |
Output is correct |
13 |
Correct |
585 ms |
3820 KB |
Output is correct |
14 |
Correct |
587 ms |
4076 KB |
Output is correct |
15 |
Correct |
638 ms |
4972 KB |
Output is correct |
16 |
Correct |
619 ms |
4076 KB |
Output is correct |
17 |
Correct |
635 ms |
4340 KB |
Output is correct |
18 |
Correct |
381 ms |
5868 KB |
Output is correct |
19 |
Correct |
566 ms |
2924 KB |
Output is correct |
20 |
Correct |
579 ms |
4588 KB |
Output is correct |
21 |
Correct |
600 ms |
5212 KB |
Output is correct |
22 |
Correct |
701 ms |
5144 KB |
Output is correct |
23 |
Correct |
703 ms |
4332 KB |
Output is correct |
24 |
Correct |
698 ms |
4060 KB |
Output is correct |
25 |
Correct |
654 ms |
6024 KB |
Output is correct |
26 |
Correct |
735 ms |
4972 KB |
Output is correct |
27 |
Correct |
801 ms |
4220 KB |
Output is correct |
28 |
Correct |
401 ms |
6636 KB |
Output is correct |
29 |
Correct |
583 ms |
2668 KB |
Output is correct |
30 |
Correct |
651 ms |
4772 KB |
Output is correct |
31 |
Correct |
778 ms |
4588 KB |
Output is correct |
32 |
Correct |
722 ms |
4664 KB |
Output is correct |
33 |
Correct |
598 ms |
3436 KB |
Output is correct |
34 |
Correct |
690 ms |
3692 KB |
Output is correct |
35 |
Correct |
742 ms |
4108 KB |
Output is correct |
36 |
Correct |
386 ms |
2668 KB |
Output is correct |
37 |
Correct |
678 ms |
4700 KB |
Output is correct |
38 |
Correct |
647 ms |
2552 KB |
Output is correct |
39 |
Correct |
699 ms |
3820 KB |
Output is correct |
40 |
Correct |
695 ms |
3692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
114 ms |
27044 KB |
Output is correct |
12 |
Correct |
115 ms |
27044 KB |
Output is correct |
13 |
Correct |
123 ms |
27044 KB |
Output is correct |
14 |
Correct |
152 ms |
27044 KB |
Output is correct |
15 |
Correct |
123 ms |
27044 KB |
Output is correct |
16 |
Correct |
145 ms |
27044 KB |
Output is correct |
17 |
Correct |
139 ms |
27044 KB |
Output is correct |
18 |
Correct |
98 ms |
27044 KB |
Output is correct |
19 |
Correct |
115 ms |
27044 KB |
Output is correct |
20 |
Correct |
120 ms |
27044 KB |
Output is correct |
21 |
Correct |
137 ms |
27044 KB |
Output is correct |
22 |
Correct |
140 ms |
27044 KB |
Output is correct |
23 |
Correct |
113 ms |
27044 KB |
Output is correct |
24 |
Correct |
130 ms |
27044 KB |
Output is correct |
25 |
Correct |
137 ms |
27044 KB |
Output is correct |
26 |
Correct |
98 ms |
27044 KB |
Output is correct |
27 |
Correct |
119 ms |
27044 KB |
Output is correct |
28 |
Correct |
112 ms |
27044 KB |
Output is correct |
29 |
Correct |
120 ms |
27044 KB |
Output is correct |
30 |
Correct |
125 ms |
27044 KB |
Output is correct |
31 |
Correct |
118 ms |
27056 KB |
Output is correct |
32 |
Correct |
146 ms |
27044 KB |
Output is correct |
33 |
Correct |
137 ms |
27044 KB |
Output is correct |
34 |
Correct |
100 ms |
27044 KB |
Output is correct |
35 |
Correct |
128 ms |
27044 KB |
Output is correct |
36 |
Correct |
129 ms |
27044 KB |
Output is correct |
37 |
Correct |
130 ms |
27044 KB |
Output is correct |
38 |
Correct |
131 ms |
27044 KB |
Output is correct |
39 |
Correct |
127 ms |
27044 KB |
Output is correct |
40 |
Correct |
127 ms |
27044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
592 ms |
4972 KB |
Output is correct |
12 |
Correct |
630 ms |
4588 KB |
Output is correct |
13 |
Correct |
585 ms |
3820 KB |
Output is correct |
14 |
Correct |
587 ms |
4076 KB |
Output is correct |
15 |
Correct |
638 ms |
4972 KB |
Output is correct |
16 |
Correct |
619 ms |
4076 KB |
Output is correct |
17 |
Correct |
635 ms |
4340 KB |
Output is correct |
18 |
Correct |
381 ms |
5868 KB |
Output is correct |
19 |
Correct |
566 ms |
2924 KB |
Output is correct |
20 |
Correct |
579 ms |
4588 KB |
Output is correct |
21 |
Correct |
600 ms |
5212 KB |
Output is correct |
22 |
Correct |
701 ms |
5144 KB |
Output is correct |
23 |
Correct |
703 ms |
4332 KB |
Output is correct |
24 |
Correct |
698 ms |
4060 KB |
Output is correct |
25 |
Correct |
654 ms |
6024 KB |
Output is correct |
26 |
Correct |
735 ms |
4972 KB |
Output is correct |
27 |
Correct |
801 ms |
4220 KB |
Output is correct |
28 |
Correct |
401 ms |
6636 KB |
Output is correct |
29 |
Correct |
583 ms |
2668 KB |
Output is correct |
30 |
Correct |
651 ms |
4772 KB |
Output is correct |
31 |
Correct |
778 ms |
4588 KB |
Output is correct |
32 |
Correct |
722 ms |
4664 KB |
Output is correct |
33 |
Correct |
598 ms |
3436 KB |
Output is correct |
34 |
Correct |
690 ms |
3692 KB |
Output is correct |
35 |
Correct |
742 ms |
4108 KB |
Output is correct |
36 |
Correct |
386 ms |
2668 KB |
Output is correct |
37 |
Correct |
678 ms |
4700 KB |
Output is correct |
38 |
Correct |
647 ms |
2552 KB |
Output is correct |
39 |
Correct |
699 ms |
3820 KB |
Output is correct |
40 |
Correct |
695 ms |
3692 KB |
Output is correct |
41 |
Correct |
114 ms |
27044 KB |
Output is correct |
42 |
Correct |
115 ms |
27044 KB |
Output is correct |
43 |
Correct |
123 ms |
27044 KB |
Output is correct |
44 |
Correct |
152 ms |
27044 KB |
Output is correct |
45 |
Correct |
123 ms |
27044 KB |
Output is correct |
46 |
Correct |
145 ms |
27044 KB |
Output is correct |
47 |
Correct |
139 ms |
27044 KB |
Output is correct |
48 |
Correct |
98 ms |
27044 KB |
Output is correct |
49 |
Correct |
115 ms |
27044 KB |
Output is correct |
50 |
Correct |
120 ms |
27044 KB |
Output is correct |
51 |
Correct |
137 ms |
27044 KB |
Output is correct |
52 |
Correct |
140 ms |
27044 KB |
Output is correct |
53 |
Correct |
113 ms |
27044 KB |
Output is correct |
54 |
Correct |
130 ms |
27044 KB |
Output is correct |
55 |
Correct |
137 ms |
27044 KB |
Output is correct |
56 |
Correct |
98 ms |
27044 KB |
Output is correct |
57 |
Correct |
119 ms |
27044 KB |
Output is correct |
58 |
Correct |
112 ms |
27044 KB |
Output is correct |
59 |
Correct |
120 ms |
27044 KB |
Output is correct |
60 |
Correct |
125 ms |
27044 KB |
Output is correct |
61 |
Correct |
118 ms |
27056 KB |
Output is correct |
62 |
Correct |
146 ms |
27044 KB |
Output is correct |
63 |
Correct |
137 ms |
27044 KB |
Output is correct |
64 |
Correct |
100 ms |
27044 KB |
Output is correct |
65 |
Correct |
128 ms |
27044 KB |
Output is correct |
66 |
Correct |
129 ms |
27044 KB |
Output is correct |
67 |
Correct |
130 ms |
27044 KB |
Output is correct |
68 |
Correct |
131 ms |
27044 KB |
Output is correct |
69 |
Correct |
127 ms |
27044 KB |
Output is correct |
70 |
Correct |
127 ms |
27044 KB |
Output is correct |
71 |
Correct |
921 ms |
31232 KB |
Output is correct |
72 |
Correct |
964 ms |
31328 KB |
Output is correct |
73 |
Correct |
1062 ms |
29792 KB |
Output is correct |
74 |
Correct |
1458 ms |
30304 KB |
Output is correct |
75 |
Correct |
993 ms |
32348 KB |
Output is correct |
76 |
Correct |
1427 ms |
30468 KB |
Output is correct |
77 |
Correct |
1321 ms |
31584 KB |
Output is correct |
78 |
Correct |
594 ms |
35476 KB |
Output is correct |
79 |
Correct |
877 ms |
29280 KB |
Output is correct |
80 |
Correct |
942 ms |
32456 KB |
Output is correct |
81 |
Correct |
1220 ms |
32352 KB |
Output is correct |
82 |
Correct |
1392 ms |
31584 KB |
Output is correct |
83 |
Correct |
905 ms |
30616 KB |
Output is correct |
84 |
Correct |
1114 ms |
31416 KB |
Output is correct |
85 |
Correct |
1334 ms |
31508 KB |
Output is correct |
86 |
Correct |
575 ms |
29280 KB |
Output is correct |
87 |
Correct |
954 ms |
32304 KB |
Output is correct |
88 |
Correct |
882 ms |
29280 KB |
Output is correct |
89 |
Correct |
1078 ms |
31072 KB |
Output is correct |
90 |
Correct |
1089 ms |
31328 KB |
Output is correct |
91 |
Correct |
898 ms |
30560 KB |
Output is correct |
92 |
Correct |
1508 ms |
31584 KB |
Output is correct |
93 |
Correct |
1336 ms |
31820 KB |
Output is correct |
94 |
Correct |
577 ms |
29280 KB |
Output is correct |
95 |
Correct |
1185 ms |
31380 KB |
Output is correct |
96 |
Correct |
1239 ms |
31584 KB |
Output is correct |
97 |
Correct |
1194 ms |
31460 KB |
Output is correct |
98 |
Correct |
1181 ms |
31584 KB |
Output is correct |
99 |
Correct |
1185 ms |
31484 KB |
Output is correct |
100 |
Correct |
1256 ms |
31508 KB |
Output is correct |