#P9938. Determining Researcher Seniority
Determining Researcher Seniority
Determining Researcher Seniority
Bessie is applying for a graduate program in computer science and has received an interview invitation from a prestigious laboratory. However, to avoid offending anyone, she wants to determine the relative seniority of the laboratory's N members (with 1 ≤ N ≤ 100) before the interview. No two members have the same seniority, but it might be tricky to figure out their ranks. For this, Bessie studies publications of the lab.
Each publication contains a list of authors, which is a permutation of all N lab members. The list is sorted in decreasing order of contribution. If two researchers contributed equally, then they are ordered in lexicographical order. Since more senior researchers have extra administrative responsibilities, a more senior researcher will never contribute more than a more junior researcher. In other words, if researcher x is more senior than researcher y, then in any publication we must have:
[ \text{contrib}(x) \leq \text{contrib}(y)]
Thus if in a publication an author A appears before B and it is not possible for the two contributions to be tied (i.e. the lexicographical order does not align), then we deduce that B is more senior than A.
Given K publications (with 1 ≤ K ≤ 100), determine for every pair of lab members who is more senior if it can be deduced from the publications.
inputFormat
The first line contains two integers N and K. The second line contains N distinct lab member names separated by spaces. Each of the next K lines contains a permutation of the N names, representing a publication's author list in decreasing order of contribution.
outputFormat
Output an N × N matrix. For the ith lab member (in the order given in the input) and the jth lab member, output:
- 'B' if i and j are the same member,
- '1' if the ith lab member is definitely more senior than the jth,
- '0' if the ith lab member is definitely more junior than the jth,
- '?' if the seniority relationship cannot be determined.
sample
3 1
Elsie Mildred Dean
Elsie Mildred Dean
B?0
?B0
11B
</p>