| <p> | |
| <strong>This problem statement differs from that of Leapfrog Ch. 1 in only one spot, highlighted in bold below.</strong> | |
| </p> | |
| <p> | |
| A colony of frogs peacefully resides in a pond. The colony is led by a single Alpha Frog, and also includes 0 or more Beta Frogs. | |
| In order to be a good leader, the Alpha Frog diligently studies the high art of fractions every day. | |
| </p> | |
| <p> | |
| There are <strong>N</strong> lilypads in a row on the pond's surface, numbered 1 to <strong>N</strong> from left to right, each of which is large enough to fit at most one frog at a time. | |
| Today, the Alpha Frog finds itself on the leftmost lilypad, and must leap its way to the rightmost lilypad before it can begin its fractions practice. | |
| </p> | |
| <p> | |
| The initial state of each lilypad <em>i</em> is described by a character <strong>L<sub>i</sub></strong>, which is one of the following: | |
| </p> | |
| <ul> | |
| <li> "<code>A</code>": Occupied by the Alpha Frog (it's guaranteed that <strong>L<sub>i</sub></strong> = "<code>A</code>" if and only if <em>i</em> = 1) </li> | |
| <li> "<code>B</code>": Occupied by a Beta Frog </li> | |
| <li> "<code>.</code>": Unoccupied </li> | |
| </ul> | |
| <p> | |
| At each point in time, one of the following things may occur: | |
| </p> | |
| <p> | |
| 1) The Alpha Frog may leap over one or more lilypads immediately to either its left or right which are occupied by Beta Frogs, | |
| and land on the next unoccupied lilypad past them, if such a lilypad exists. | |
| The Alpha Frog must leap over at least one Beta Frog; it may not just leap to an adjacent lilypad. | |
| <strong>Note that, unlike in Leapfrog Ch. 1, the Alpha Frog may leap to either its left or right.</strong> | |
| </p> | |
| <p> | |
| 2) Any Beta Frog may leap to the next lilypad to either its left or right, if such a lilypad exists and is unoccupied. | |
| </p> | |
| <p> | |
| Assuming the frogs all cooperate, determine whether or not it's possible for the Alpha Frog to ever reach the rightmost lilypad and begin its daily fractions practice. | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of days on which the Alpha Frog studies fractions. | |
| For each day, there is a single line containing the length-<strong>N</strong> string <strong>L</strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <em>i</em>th day, print a line containing "Case #<em>i</em>: " | |
| followed by a single character: "<code>Y</code>" if the Alpha Frog can reach the rightmost lilypad, or "<code>N</code>" otherwise. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 500 <br /> | |
| 2 ≤ <strong>N</strong> ≤ 5,000 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first case, the Alpha Frog can't leap anywhere. | |
| </p> | |
| <p> | |
| In the second case, the Alpha Frog can leap over the Beta Frog to reach the rightmost lilypad. | |
| </p> | |
| <p> | |
| In the third case, neither the Alpha Frog nor either of the Beta Frogs can leap anywhere. | |
| </p> | |
| <p> | |
| In the fourth case, if the first Beta Frog leaps one lilypad to the left, and then the second Beta Frog also leaps one lilypad to the left, | |
| then the Alpha Frog can leap over both of them to reach the rightmost lilypad. | |
| </p> | |