Magic Cards
InterviewTime limit3sMemory limit2048 MB
Given K cards that each list numbers from 1 to N, and each friend's yes/no answers, find the number each friend picked, or 0 if it is not unique.
- Level
Medium4 of 10
- Topics
- Hash map, Bit manipulation, Array
- Solved
- No attempts yet
Problem
Chansu and Junsu are friends at International College of Programming Convergence. One day, Chansu met Junsu and said that "I'll do a magic trick for you. Pick any number between and , and don't tell me your number. Just keep it in your mind." Junsu chose in mind. Chansu then showed Junsu the following four cards one by one, asking "Is there your number in this card?" at each time.
Junsu answered "Yes, yes, no, yes" in this order. After Chansu made some theatrical gestures with his arms and legs for a while, he finally shouted, "I've got your number. It is ." Junsu was surprised because it was exactly the number he had kept in mind. Chansu did not reveal the secret of the trick. He only said, "These cards have a great magic power, so they can read your mind and tell me something only in a magical language, which only I can understand." How does this work? Can you figure out the secret? Now, you are to write a program that answers the number in your friends' minds. The trick can be generalized as follows. You have magic cards, and each card has exactly integers between and , possibly with some repeats. You perform the trick on friends. From the yes/no sequences of the friends, you pick out the correct numbers.
Input
The first line contains four integers , , , and (, , , ). Each of the following lines contains integers between and , which are the numbers written on one magic card. Each of the following lines contains a string of length over Y and N. A Y means "yes" and an N means "no". All answers are correctly given according to the numbers chosen in mind.
Output
Print exactly lines. The -th line contains the number in the -th friend's mind. If the number of the -th friend cannot be identified uniquely, print 0 on that line.