P9938 [USACO21OPEN] Acowdemia II B
Description
Bessie is applying to a computer science graduate program and has received an interview invitation from a long-established and well-known computer science lab. However, to avoid offending anyone, Bessie wants to first determine the relative seniority of the lab’s $N$ current members ($1\le N\le 100$). No two lab members have the same seniority, but figuring out who is more senior may not be easy. To do this, Bessie will investigate the lab’s publications.
Each publication contains an author list, which is a permutation of all $N$ lab members. The list is sorted in decreasing order by each member’s contribution to that paper. If multiple researchers contributed equally, they are ordered lexicographically. Since more senior lab members have more management responsibilities, a more senior researcher never contributes more than a less senior researcher.
For example, in a lab with the less senior student Elsie, the more senior professor Mildred, and the very senior professor Dean, there could be a paper Elsie-Mildred-Dean if they made unequal contributions (that is, Elsie contributed more than Mildred, and Mildred more than Dean). However, there could also be a paper Elsie-Dean-Mildred if Mildred and Dean contributed equally, and Elsie contributed more.
Given the lab’s $K$ publications ($1\le K\le 100$), for every pair of researchers in the lab, help Bessie determine who is more senior whenever possible.
Input Format
The first line contains two integers $K$ and $N$.
The second line contains $N$ space-separated strings, the names of the lab members. Each string consists of lowercase letters and has length at most $10$.
The next $K$ lines each contain $N$ space-separated strings, representing the author list of one publication.
Output Format
Output $N$ lines, each containing $N$ characters. In the $i$-th line, for all $j\neq i$, character $j$ should be `1` if it can be determined that member $i$ is more senior than member $j$, `0` if it can be determined that member $i$ is less senior than member $j$, and `?` if it cannot be determined from the given publications.
Character $i$ of the $i$-th line should be `B`, because this is Bessie’s favorite letter.
Explanation/Hint
### Sample Explanation 1
In this sample, the single paper elsie-mildred-dean does not provide enough information to determine whether Elsie is more senior or less senior than Mildred. However, we can infer that Dean must be more senior than both of them, so both seniority orders Elsie