#P12102. Office Hours Analysis
Office Hours Analysis
Office Hours Analysis
Two math professors have their office hours on the same day. For the whole semester, each professor has fixed a permutation (order) of n students (numbered 1 through n) in which the students should visit him. Today only a subset A of the students visited the university – all students in A visited both professors while those not in A visited none.
For each professor, when a student visited he recorded his visit in the order of his established permutation after deleting those students who did not come. However, since a professor may not know every student at the beginning of the year, if he knows the student he writes the student’s identifier; otherwise he writes -1
as a placeholder. Thus, each professor ends up with a list of length m (where m = |A|) which is the subsequence (with the same order as the professor’s permutation) of the students in A but with some entries replaced by -1
.
More formally, let the first professor’s permutation be P = [p1, p2, …, pn] and the professor’s recorded list for today be L1 = [a1, a2, …, am]. When we extract the subsequence of P corresponding to A (i.e. the students who came) we get some sequence S1 = [s1, s2, …, sm]. It is known that for every index i (1 ≤ i ≤ m), if ai ≠ -1 then si = ai. The second professor’s data is given similarly with permutation Q and list L2.
Your task is to decide for each student whether the data forces him to have visited today, whether he definitely did not (i.e. in every valid scenario he is absent), or whether his status cannot be determined. Note that it is possible that the professors’ data is inconsistent, i.e. no subset A could have produced the two lists.
Input/Output specifications below describe the input and output formats.
inputFormat
The input is given in several lines:
- The first line contains an integer n (the total number of students).
- The second line contains n distinct integers, a permutation P representing the first professor’s order.
- The third line contains n distinct integers, a permutation Q representing the second professor’s order.
- The fourth line contains m space‐separated integers forming the list L1 (each integer is either a student id or
-1
), where m is the number of students who visited today. - The fifth line contains m space‐separated integers forming the list L2 (each integer is either a student id or
-1
).
You may assume that 1 ≤ m ≤ n, and that the two lists have equal length. The positions of the fixed (non- -1
) entries in each list indicate that in the sorted order (according to the professor’s permutation) the ith element is forced to be that student.
outputFormat
If the data is inconsistent (i.e. no valid subset A exists satisfying both professors’ records), output a single line containing the word inconsistent
. Otherwise, output a single line containing n tokens (separated by a single space); the ith token should be:
YES
if student i definitely visited (i.e. is in every valid subset A),NO
if student i definitely did not visit (i.e. is absent in every valid subset A), orNOT SURE
if it cannot be determined whether student i visited.
The determination is based on the following idea:
- The entries in each professor’s list that are not
-1
force the corresponding student to be in A (the fixed set for that professor). Let F1 and F2 be these sets, and let F = F1 ∪ F2. - The size of A is m, so exactly m - |F| students must be chosen from the remaining (optional) students.
- However, due to the ordering constraints induced by the professors’ permutations, some optional students may be forced to be chosen, and some may be impossible to choose. In our solution we compute an eligibility condition based on the position (rank) of a student in each permutation. In particular, if a professor has a fixed (non-
-1
) entry then any optional student that would appear before the first fixed student in that professor’s order cannot be chosen. Using these ideas we decide for each student whether he must be in every valid A (outputYES
), cannot be chosen at all (outputNO
), or may or may not be chosen (outputNOT SURE
).
sample
4
1 2 3 4
3 2 4 1
1 -1 -1
3 -1 1
YES NOT SURE YES NOT SURE