How many teams?

시간 제한1초메모리 제한2048 MB

요약
K개 비트로 표현된 N명 학생의 기술 집합이 주어질 때, 세 명을 골라 합집합이 각 질의 부분집합과 정확히 같은 팀의 수를 센다.
난이도

어려움10점 중 8점

유형
조합론, 비트 연산, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

The WEB Programming Marathon is a competition organized by the Society of Brazilian CSS (SBC). Teams consist of exactly three members, and the main objective is to develop a project using CSS and JavaScript.

Each competitor has a subset of the KK most important skills of a frontend developer. Some examples of these skills are:

  1. Center a div (the classic frontend ritual);
  2. Master CSS without losing sanity;
  3. Remember the difference between == and ===;
  4. Invoke the mystical power of a console.log().

A university has NN students, and each student possesses a subset of the KK skills. A team’s total skill set is defined as the union of the subsets of its members.

For example, consider the following skills of three students:

member_1=1,2,member_2=2,member_3=1,4\text{member}\_1 = \\{1, 2\\}, \text{member}\_2 = \\{2\\}, \text{member}\_3 = \\{1, 4\\}

Thus, the team formed by these three students has the skill set 1,2,4\\{1, 2, 4\\}.

Professor Joãozinho, using a very advanced LLM, discovered MM special skill subsets. If a team’s skill set is exactly equal to one of these special subsets, then it has a great chance of becoming the champion.

Now, the professor wants to know, for each special subset, how many distinct teams, formed by three students, can be assembled so that the resulting skill set is exactly that subset.

입력

The first line contains two integers NN and KK (1≤N≤1051 ≤ N ≤ 10^5, 1≤K≤201 ≤ K ≤ 20), representing, respectively, the number of students and the total number of possible skills.

The next NN lines contain a binary string H_iH\_i of size KK, which represents the skill set of student ii. If the character at position jj (1≤j≤K1 ≤ j ≤ K) is 11, it means the student has skill jj; otherwise, they do not have it.

The next line contains an integer MM (1≤M≤5⋅1041 ≤ M ≤ 5 \cdot 10^4), representing the number of special subsets.

The next M lines contain a binary string E_iE\_i of size KK, which represents a special subset. If the character at position jj (1≤j≤K1 ≤ j ≤ K) is 11, it means the special subset includes skill jj; otherwise, it does not include it.

출력

The output should contain MM lines. The ii-th line should contain a single integer representing the number of distinct teams, formed by three students, whose skill set is exactly equal to E_iE\_i.

예제2

  1. 예제 1

    입력
    5 3
    010
    100
    010
    110
    010
    3
    010
    011
    110
    
    예상 출력
    1
    0
    9
    
  2. 예제 2

    입력
    3 2
    10
    01
    11
    1
    10
    
    예상 출력
    0