Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- const int SIZE = 1<<20;
- int dp[SIZE],a[SIZE];
- int main(){
- int n,q;
- scanf("%d%d",&n,&q);
- for(int i=0;i<n;i++){
- char s[24];
- scanf("%s",s);
- for(int j=0;j<20;j++)a[i]|=(int)(s[j]-'0')<<j;
- dp[a[i]]++;
- }
- for(int i=0;i<20;i++)
- for(int j=0;j<SIZE;j++)
- if((j>>i)&1)dp[j^(1<<i)]+=dp[j];
- while(q--){
- long long an=0;
- int x=0;
- char s[24];
- scanf("%s",s);
- for(int j=0;j<20;j++)x|=(int)(s[j]-'0')<<j;
- for(int i=0;i<n;i++){
- an+=dp[x^(x&a[i])];
- if((x&a[i])==x)an--;
- }
- printf("%I64d\n",an/2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment