Hat Puzzle
Time limit10sMemory limit1024 MB
Given who can see whose hat, simulate rounds of public yes/no answers over all hat configurations and output each asked setter's answer.
- Level
Medium6 of 10
- Topics
- Simulation, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
UCPC problem setters have gathered in one place to record a solution explanation and a scoreboard broadcast. Before the broadcast starts, the setters play a mind game for fun.
- The game host has many white and black hats.
- Each setter sits in an assigned chair. Every setter knows who can see whose hat, and no one can see their own hat.
- When every setter closes their eyes, the host puts one of the two colored hats on each setter. The host then says, "The number of white hats is at least and at most ."
- After that, the host asks several questions. In each question, the host asks some setters at the same time, "Do you know the color of the hat you are wearing?" All setters asked must answer at the same time. Every setter can hear what each setter answered.
Solve this game from the viewpoint of an observer who knows the hat color of every setter. Assume every setter reasons perfectly logically and makes no guesses without evidence. Find what each setter answers.
Input
The first line contains ().
Each of the next lines contains values, each either 0 or 1. The -th value on the -th line is 1 if setter can see the hat of setter , and 0 otherwise. No setter can see their own hat, so the diagonal values are 0.
The next line contains and , the minimum and maximum number of white hats announced by the host ().
The next line contains a string of length made of W and B. The -th character is W if setter wears a white hat and B otherwise. The number of W characters is between and , inclusive.
The next line contains the number of questions ().
Each of the next lines starts with , the number of setters asked in that question, followed by distinct integers , each naming a setter who is asked. All setters are asked at the same time.
Output
For each question, print one line with characters. Each character is Y if the setter answers yes, or N if the setter answers no, in the order the setters were listed in the question.