Solve the problem: “One day, an absent-minded professor gave his students a task: to…
- User
Solve the problem: “One day, an absent-minded professor gave his students a task: to select, without repetition, a random non-empty subset of objects from a set of data. The result of completing the task is a list of object numbers. He collected these lists from the students and accidentally combined them into one large list.
Now the professor cannot check each student's list separately. Then he decides that he will simply try to select lists that will ultimately yield one large resulting list. If such lists exist, all students will receive credit for completing the assignment. If not, it won’t count for anyone. Help the professor determine whether such lists exist?
Comment In the first subtest of the example, students could give the professor the following lists as an answer: [1, 2, 3], [2, 3], and [3]. Input format Each test consists of several subtests. The first line contains the natural number Q (1 ≤ Q ≤ 105) — the number of subtests.
The following is a description of the subtests. Each subtest is specified in two lines. The first of them contains three space-separated natural numbers N, M and K (1 ≤ N, M, K ≤ 105): N is the length of the list of object numbers obtained after combining, M is the number of objects in the original data set, K is the number of students. Objects in the data set are numbered from 1 to M. The second line of each subtest contains a description of a large list of objects and consists of N natural numbers ai (1 ≤ ai ≤ 105) separated by spaces—object numbers.
The sum of N for all subtests of one test does not exceed 105. Output format For each test, print the line YES if students should pass the assignment, or NO otherwise."
- Assistant
To solve this problem, we can use a hash set to keep track of the unique object numbers in the large list.
For each subtest, we iterate through the large list of object numbers. If an object number is already in the hash set, it means that it has been selected by a previous student. In this case, we print "NO" and move on to the next subtest.
If we reach the end of the large list without encountering any duplicate object numbers, we print "YES" to indicate that students should pass the assignment.
Here is the implementation in Python:
python