#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);}
int main()
{
//O(l * 2^l + q)
owo
int l,q;
cin>>l>>q;
vector<int>sub(1<<(l+1)),sup(1<<(l+1));
string snek;
for(int i=0;i<(1<<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<(1<<l);j++){
if(j&(1<<i))sub[j]+=sub[j^(1<<i)];
else sup[j]+=sup[j^(1<<i)];
}
}
while(q--){
vector<int>a,b,c;
string s;cin>>s;
ll ans = 0;
for(int i=0;i<l;i++){
if(s[i] == '?')c.pb(l-i-1);
if(s[i] == '0')a.pb(l-i-1);
if(s[i] == '1')b.pb(l-i-1);
}
if(sz(c) <= l/3){
ll cur = 0;
for(int i=0;i<l;i++)if(s[i]=='1')cur+=(1<<(l-i-1));
for(int i=0;i<(1<<sz(c));i++){
ll ncur = cur;
for(int j=0;j<sz(c);j++){
if(i&(1<<j))ncur+=(1<<c[j]);
}
ans+=snek[ncur]-'0';
}
}
else if(sz(a) <= l/3){
ll cur = 0;
for(int i=0;i<l;i++)if(s[i] == '1')cur+=(1<<(l-i-1));
for(int i=0;i<(1<<sz(a));i++){
ll ncur = cur;
int cnt = 0;
for(int j=0;j<sz(a);j++){
if(i&(1<<j)){ncur+=(1<<a[j]);cnt++;}
}
if(cnt&1)ans-=sup[ncur];
else ans+=sup[ncur];
}
}else{
ll cur = 0;
for(int i=0;i<l;i++)if(s[i] == '?')cur+=(1<<(l-i-1));
for(int mask=0;mask<(1<<sz(b));mask++){
ll ncur = cur;
int cnt = 0;
for(int j=0;j<sz(b);j++){
if(mask&(1<<j)){ncur+=(1<<b[j]);}
else cnt++;
}
if(cnt&1)ans-=sub[ncur];
else ans+=sub[ncur];
}
}
cout<<ans<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 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 |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 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 |
364 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 |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 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 |
616 ms |
4536 KB |
Output is correct |
12 |
Correct |
598 ms |
4020 KB |
Output is correct |
13 |
Correct |
708 ms |
3364 KB |
Output is correct |
14 |
Correct |
712 ms |
3364 KB |
Output is correct |
15 |
Correct |
633 ms |
4460 KB |
Output is correct |
16 |
Correct |
704 ms |
3804 KB |
Output is correct |
17 |
Correct |
705 ms |
3692 KB |
Output is correct |
18 |
Correct |
405 ms |
5612 KB |
Output is correct |
19 |
Correct |
602 ms |
2540 KB |
Output is correct |
20 |
Correct |
614 ms |
4076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 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 |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 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 |
616 ms |
4536 KB |
Output is correct |
12 |
Correct |
598 ms |
4020 KB |
Output is correct |
13 |
Correct |
708 ms |
3364 KB |
Output is correct |
14 |
Correct |
712 ms |
3364 KB |
Output is correct |
15 |
Correct |
633 ms |
4460 KB |
Output is correct |
16 |
Correct |
704 ms |
3804 KB |
Output is correct |
17 |
Correct |
705 ms |
3692 KB |
Output is correct |
18 |
Correct |
405 ms |
5612 KB |
Output is correct |
19 |
Correct |
602 ms |
2540 KB |
Output is correct |
20 |
Correct |
614 ms |
4076 KB |
Output is correct |
21 |
Correct |
658 ms |
4632 KB |
Output is correct |
22 |
Correct |
719 ms |
4844 KB |
Output is correct |
23 |
Correct |
825 ms |
3820 KB |
Output is correct |
24 |
Correct |
872 ms |
3692 KB |
Output is correct |
25 |
Correct |
743 ms |
5668 KB |
Output is correct |
26 |
Correct |
879 ms |
4188 KB |
Output is correct |
27 |
Correct |
876 ms |
4076 KB |
Output is correct |
28 |
Correct |
433 ms |
6764 KB |
Output is correct |
29 |
Correct |
664 ms |
2540 KB |
Output is correct |
30 |
Correct |
702 ms |
4868 KB |
Output is correct |
31 |
Correct |
850 ms |
4588 KB |
Output is correct |
32 |
Correct |
891 ms |
4532 KB |
Output is correct |
33 |
Correct |
720 ms |
3692 KB |
Output is correct |
34 |
Correct |
873 ms |
3776 KB |
Output is correct |
35 |
Correct |
872 ms |
4100 KB |
Output is correct |
36 |
Correct |
399 ms |
2540 KB |
Output is correct |
37 |
Correct |
664 ms |
4460 KB |
Output is correct |
38 |
Correct |
678 ms |
2540 KB |
Output is correct |
39 |
Correct |
818 ms |
3780 KB |
Output is correct |
40 |
Correct |
850 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 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 |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 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 |
106 ms |
18852 KB |
Output is correct |
12 |
Correct |
117 ms |
18852 KB |
Output is correct |
13 |
Correct |
129 ms |
18852 KB |
Output is correct |
14 |
Correct |
171 ms |
18852 KB |
Output is correct |
15 |
Correct |
119 ms |
18852 KB |
Output is correct |
16 |
Correct |
161 ms |
18852 KB |
Output is correct |
17 |
Correct |
150 ms |
18852 KB |
Output is correct |
18 |
Correct |
86 ms |
18852 KB |
Output is correct |
19 |
Correct |
112 ms |
18852 KB |
Output is correct |
20 |
Correct |
113 ms |
18852 KB |
Output is correct |
21 |
Correct |
138 ms |
18852 KB |
Output is correct |
22 |
Correct |
166 ms |
18852 KB |
Output is correct |
23 |
Correct |
118 ms |
18852 KB |
Output is correct |
24 |
Correct |
158 ms |
18852 KB |
Output is correct |
25 |
Correct |
152 ms |
18852 KB |
Output is correct |
26 |
Correct |
83 ms |
18852 KB |
Output is correct |
27 |
Correct |
105 ms |
18852 KB |
Output is correct |
28 |
Correct |
106 ms |
18852 KB |
Output is correct |
29 |
Correct |
133 ms |
18852 KB |
Output is correct |
30 |
Correct |
155 ms |
19000 KB |
Output is correct |
31 |
Correct |
110 ms |
18852 KB |
Output is correct |
32 |
Correct |
163 ms |
18852 KB |
Output is correct |
33 |
Correct |
149 ms |
18852 KB |
Output is correct |
34 |
Correct |
87 ms |
18852 KB |
Output is correct |
35 |
Correct |
136 ms |
18852 KB |
Output is correct |
36 |
Correct |
135 ms |
18852 KB |
Output is correct |
37 |
Correct |
144 ms |
19000 KB |
Output is correct |
38 |
Correct |
160 ms |
18852 KB |
Output is correct |
39 |
Correct |
140 ms |
18852 KB |
Output is correct |
40 |
Correct |
146 ms |
18888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 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 |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 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 |
616 ms |
4536 KB |
Output is correct |
12 |
Correct |
598 ms |
4020 KB |
Output is correct |
13 |
Correct |
708 ms |
3364 KB |
Output is correct |
14 |
Correct |
712 ms |
3364 KB |
Output is correct |
15 |
Correct |
633 ms |
4460 KB |
Output is correct |
16 |
Correct |
704 ms |
3804 KB |
Output is correct |
17 |
Correct |
705 ms |
3692 KB |
Output is correct |
18 |
Correct |
405 ms |
5612 KB |
Output is correct |
19 |
Correct |
602 ms |
2540 KB |
Output is correct |
20 |
Correct |
614 ms |
4076 KB |
Output is correct |
21 |
Correct |
658 ms |
4632 KB |
Output is correct |
22 |
Correct |
719 ms |
4844 KB |
Output is correct |
23 |
Correct |
825 ms |
3820 KB |
Output is correct |
24 |
Correct |
872 ms |
3692 KB |
Output is correct |
25 |
Correct |
743 ms |
5668 KB |
Output is correct |
26 |
Correct |
879 ms |
4188 KB |
Output is correct |
27 |
Correct |
876 ms |
4076 KB |
Output is correct |
28 |
Correct |
433 ms |
6764 KB |
Output is correct |
29 |
Correct |
664 ms |
2540 KB |
Output is correct |
30 |
Correct |
702 ms |
4868 KB |
Output is correct |
31 |
Correct |
850 ms |
4588 KB |
Output is correct |
32 |
Correct |
891 ms |
4532 KB |
Output is correct |
33 |
Correct |
720 ms |
3692 KB |
Output is correct |
34 |
Correct |
873 ms |
3776 KB |
Output is correct |
35 |
Correct |
872 ms |
4100 KB |
Output is correct |
36 |
Correct |
399 ms |
2540 KB |
Output is correct |
37 |
Correct |
664 ms |
4460 KB |
Output is correct |
38 |
Correct |
678 ms |
2540 KB |
Output is correct |
39 |
Correct |
818 ms |
3780 KB |
Output is correct |
40 |
Correct |
850 ms |
3564 KB |
Output is correct |
41 |
Correct |
106 ms |
18852 KB |
Output is correct |
42 |
Correct |
117 ms |
18852 KB |
Output is correct |
43 |
Correct |
129 ms |
18852 KB |
Output is correct |
44 |
Correct |
171 ms |
18852 KB |
Output is correct |
45 |
Correct |
119 ms |
18852 KB |
Output is correct |
46 |
Correct |
161 ms |
18852 KB |
Output is correct |
47 |
Correct |
150 ms |
18852 KB |
Output is correct |
48 |
Correct |
86 ms |
18852 KB |
Output is correct |
49 |
Correct |
112 ms |
18852 KB |
Output is correct |
50 |
Correct |
113 ms |
18852 KB |
Output is correct |
51 |
Correct |
138 ms |
18852 KB |
Output is correct |
52 |
Correct |
166 ms |
18852 KB |
Output is correct |
53 |
Correct |
118 ms |
18852 KB |
Output is correct |
54 |
Correct |
158 ms |
18852 KB |
Output is correct |
55 |
Correct |
152 ms |
18852 KB |
Output is correct |
56 |
Correct |
83 ms |
18852 KB |
Output is correct |
57 |
Correct |
105 ms |
18852 KB |
Output is correct |
58 |
Correct |
106 ms |
18852 KB |
Output is correct |
59 |
Correct |
133 ms |
18852 KB |
Output is correct |
60 |
Correct |
155 ms |
19000 KB |
Output is correct |
61 |
Correct |
110 ms |
18852 KB |
Output is correct |
62 |
Correct |
163 ms |
18852 KB |
Output is correct |
63 |
Correct |
149 ms |
18852 KB |
Output is correct |
64 |
Correct |
87 ms |
18852 KB |
Output is correct |
65 |
Correct |
136 ms |
18852 KB |
Output is correct |
66 |
Correct |
135 ms |
18852 KB |
Output is correct |
67 |
Correct |
144 ms |
19000 KB |
Output is correct |
68 |
Correct |
160 ms |
18852 KB |
Output is correct |
69 |
Correct |
140 ms |
18852 KB |
Output is correct |
70 |
Correct |
146 ms |
18888 KB |
Output is correct |
71 |
Correct |
1062 ms |
23140 KB |
Output is correct |
72 |
Correct |
1170 ms |
23412 KB |
Output is correct |
73 |
Correct |
1417 ms |
21652 KB |
Output is correct |
74 |
Execution timed out |
2093 ms |
21980 KB |
Time limit exceeded |
75 |
Halted |
0 ms |
0 KB |
- |