Books
Time limit6sMemory limit1024 MB
For each candidate pair of students, find every book set whose books the two students can jointly cover, splitting the books between them.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Dynamic programming
- Solved
- No attempts yet
Problem
The Noname State University (NSU) is preparing for a new type of programming contest. Each university in this contest can be represented only by a single team of two students. There is also the official list of books which the contestants must read to perform successfully. There is little time left before the contest, and not every student is able to read all books in time.
Every student knows for each set of books whether she can read it in time. There are students willing to participate in the contest in the NSU. The coach prepared a list of candidate teams. To choose a single team for the contest, she wants to know each team's reading capability.
A team has read a book if at least one member of the team has read it. Your task is to find, for each candidate team and for each set of books, whether the team members can plan their training so that the team will have read all the books of this set in time.
Input
The first line of the input contains three integers: (number of books), (number of students), and (number of candidate teams). The constraints are , , and . Zero-based numbering is used everywhere in this problem.
The -th of the next lines defines the capabilities of the -th student. The capabilities are a string of length containing 0's and 1's. The -th character of the string is 1 if and only if the student can read the set of books with bitmask in time. The bitmask is defined as follows.
Number the books from 0 to . Let be a set of books, and let if book belongs to , and otherwise. The bitmask of is The -th student can read in time if and only if the -th character of is 1.
The -th of the next lines describes the -th candidate team. It contains two integers and , the numbers of the two students in the team (, ).
The capabilities satisfy two guarantees. First, if a student can read a set of books, she can read every subset of it. Second, a student can always read the empty set, so the first character of her string is always 1.
Output
Print lines, each containing characters 0 or 1. The -th line gives the capabilities of the -th team in the same format as the students' strings in the input. The -th character of the -th line is 1 if and only if the team can read the set of books with bitmask in time.
Hint
The 0-th student can read one of the following sets: , , , , , . The first student can only read book 0 (or nothing). The second student can read either book 0 or book 2 (or nothing). The third and fourth students can read any single book (or nothing).
The 0-th team is able to read all the books if student 0 reads books and student 1 reads book 0. It is easy to check that the team can also read any other set of books.
The 1st team can read books 0 and 2 if its members read different books. The team can also read any subset of .
In the 2nd team, each member can read at most one book. Hence, the team together can read any set of two or fewer books.