#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);}
ll pw[22] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048572,2097152};
int main()
{
owo
ll l,q;
cin>>l>>q;
vector<ll>sub(pw[l+1]),sup(pw[l+1]);
string snek;
for(ll i=0;i<pw[l];i++){
char c;cin>>c;
sub[i]+=c-'0';
sup[i]+=c-'0';
snek+=c;
}
for(ll i=0;i<l;i++){
for(ll 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--){
vector<ll>a,b,c;
string s;cin>>s;
ll ans = 0;
for(ll i=0;i<l;i++){
if(s[i] == '?')c.pb(l-i-1);
else if(s[i] == '0')a.pb(l-i-1);
else b.pb(l-i-1);
}
ll mn = min({sz(a),sz(b),sz(c)});
if(sz(c) == mn){
ll cur = 0;
for(ll i=0;i<l;i++)if(s[i]=='1')cur+=(pw[l-i-1]);
for(ll i=0;i<pw[sz(c)];i++){
ll ncur = cur;
for(ll j=0;j<sz(c);j++){
if(i&pw[j])ncur+=pw[c[j]];
}
ans+=snek[ncur]-'0';
}
}
else if(sz(a) == mn){
ll cur = 0;
for(ll i=0;i<l;i++)if(s[i] == '1')cur+=(pw[l-i-1]);
for(ll i=0;i<pw[sz(a)];i++){
ll ncur = cur;
ll cnt = 0;
for(ll j=0;j<sz(a);j++){
if(i&pw[j]){ncur+=pw[a[j]];cnt++;}
}
if(cnt&1)ans-=sup[ncur];
else ans+=sup[ncur];
}
}else{
ll cur = 0;
for(ll i=0;i<l;i++)if(s[i] == '?')cur+=(pw[l-i-1]);
for(ll mask=0;mask<pw[sz(b)];mask++){
ll ncur = cur;
ll cnt = 0;
for(ll j=0;j<sz(b);j++){
if(mask&pw[j]){ncur+=pw[b[j]];}
else cnt++;
}
if(cnt&1)ans-=sub[ncur];
else ans+=sub[ncur];
}
}
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
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 |
2 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 |
# |
Verdict |
Execution time |
Memory |
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 |
2 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 |
613 ms |
4436 KB |
Output is correct |
12 |
Correct |
592 ms |
4076 KB |
Output is correct |
13 |
Correct |
658 ms |
3308 KB |
Output is correct |
14 |
Correct |
673 ms |
3564 KB |
Output is correct |
15 |
Correct |
625 ms |
4460 KB |
Output is correct |
16 |
Correct |
699 ms |
3820 KB |
Output is correct |
17 |
Correct |
699 ms |
3564 KB |
Output is correct |
18 |
Correct |
412 ms |
5484 KB |
Output is correct |
19 |
Correct |
608 ms |
2412 KB |
Output is correct |
20 |
Correct |
585 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
2 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 |
613 ms |
4436 KB |
Output is correct |
12 |
Correct |
592 ms |
4076 KB |
Output is correct |
13 |
Correct |
658 ms |
3308 KB |
Output is correct |
14 |
Correct |
673 ms |
3564 KB |
Output is correct |
15 |
Correct |
625 ms |
4460 KB |
Output is correct |
16 |
Correct |
699 ms |
3820 KB |
Output is correct |
17 |
Correct |
699 ms |
3564 KB |
Output is correct |
18 |
Correct |
412 ms |
5484 KB |
Output is correct |
19 |
Correct |
608 ms |
2412 KB |
Output is correct |
20 |
Correct |
585 ms |
4076 KB |
Output is correct |
21 |
Correct |
656 ms |
4752 KB |
Output is correct |
22 |
Correct |
683 ms |
4844 KB |
Output is correct |
23 |
Correct |
795 ms |
3820 KB |
Output is correct |
24 |
Correct |
842 ms |
3772 KB |
Output is correct |
25 |
Correct |
725 ms |
5612 KB |
Output is correct |
26 |
Correct |
873 ms |
4332 KB |
Output is correct |
27 |
Correct |
855 ms |
4204 KB |
Output is correct |
28 |
Correct |
441 ms |
6636 KB |
Output is correct |
29 |
Correct |
642 ms |
2636 KB |
Output is correct |
30 |
Correct |
697 ms |
4808 KB |
Output is correct |
31 |
Correct |
843 ms |
5100 KB |
Output is correct |
32 |
Correct |
883 ms |
4716 KB |
Output is correct |
33 |
Correct |
692 ms |
3564 KB |
Output is correct |
34 |
Correct |
850 ms |
3688 KB |
Output is correct |
35 |
Correct |
868 ms |
4204 KB |
Output is correct |
36 |
Correct |
411 ms |
2708 KB |
Output is correct |
37 |
Correct |
653 ms |
4588 KB |
Output is correct |
38 |
Correct |
701 ms |
2796 KB |
Output is correct |
39 |
Correct |
815 ms |
3948 KB |
Output is correct |
40 |
Correct |
851 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
2 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 |
Incorrect |
132 ms |
35236 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
2 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 |
613 ms |
4436 KB |
Output is correct |
12 |
Correct |
592 ms |
4076 KB |
Output is correct |
13 |
Correct |
658 ms |
3308 KB |
Output is correct |
14 |
Correct |
673 ms |
3564 KB |
Output is correct |
15 |
Correct |
625 ms |
4460 KB |
Output is correct |
16 |
Correct |
699 ms |
3820 KB |
Output is correct |
17 |
Correct |
699 ms |
3564 KB |
Output is correct |
18 |
Correct |
412 ms |
5484 KB |
Output is correct |
19 |
Correct |
608 ms |
2412 KB |
Output is correct |
20 |
Correct |
585 ms |
4076 KB |
Output is correct |
21 |
Correct |
656 ms |
4752 KB |
Output is correct |
22 |
Correct |
683 ms |
4844 KB |
Output is correct |
23 |
Correct |
795 ms |
3820 KB |
Output is correct |
24 |
Correct |
842 ms |
3772 KB |
Output is correct |
25 |
Correct |
725 ms |
5612 KB |
Output is correct |
26 |
Correct |
873 ms |
4332 KB |
Output is correct |
27 |
Correct |
855 ms |
4204 KB |
Output is correct |
28 |
Correct |
441 ms |
6636 KB |
Output is correct |
29 |
Correct |
642 ms |
2636 KB |
Output is correct |
30 |
Correct |
697 ms |
4808 KB |
Output is correct |
31 |
Correct |
843 ms |
5100 KB |
Output is correct |
32 |
Correct |
883 ms |
4716 KB |
Output is correct |
33 |
Correct |
692 ms |
3564 KB |
Output is correct |
34 |
Correct |
850 ms |
3688 KB |
Output is correct |
35 |
Correct |
868 ms |
4204 KB |
Output is correct |
36 |
Correct |
411 ms |
2708 KB |
Output is correct |
37 |
Correct |
653 ms |
4588 KB |
Output is correct |
38 |
Correct |
701 ms |
2796 KB |
Output is correct |
39 |
Correct |
815 ms |
3948 KB |
Output is correct |
40 |
Correct |
851 ms |
3820 KB |
Output is correct |
41 |
Incorrect |
132 ms |
35236 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |