Good Bye 2025
A
Yes or Yes
Codeforces
800
原题
←B →
翻译中…

Last Christmas, your friend Fernando gifted you a string $s$ consisting only of the characters $\mathtt{Y}$ and $\mathtt{N}$, representing "Yes" and "No", respectively.

翻译中…

You can repeatedly apply the following operation on $s$:

翻译中…
  • Choose any two adjacent characters and replace them with their logical OR.
翻译中…

Formally, in each operation, you can choose an index $i$ ($1 \leq i \leq |s|-1$), remove the characters $s_i$ and $s_{i+1}$, then insert:

翻译中…
  • A single $\mathtt{Y}$ if at least one of $s_i$ or $s_{i+1}$ is $\mathtt{Y}$;
  • A single $\mathtt{N}$ if both $s_i$ and $s_{i+1}$ are $\mathtt{N}$.
翻译中…

Note that after each operation, the length of $s$ decreases by $1$.

翻译中…

Unfortunately, Fernando does not want you to combine "Yes OR Yes", as he has experienced trauma relating to a certain song.

翻译中…

Determine whether it is possible to reduce $s$ to a single character by repeatedly applying the operation above, without ever combining two $\mathtt{Y}$'s.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The only line of each test case contains the string $s$ ($2\le |s|\le 100$). It is guaranteed that $s_i = \mathtt{Y}$ or $\mathtt{N}$.

翻译中…

Output

翻译中…

For each test case, print "YES" if the string can be reduced to a single character by repeatedly applying the described operation, and "NO" otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In the first test case, you cannot combine $s_1$ and $s_2$ since they are both $\mathtt{Y}$. Thus, the answer is NO.

翻译中…

In the third test case, the following is a valid sequence of operations: $\mathtt{\underline{NN}Y}\to\mathtt{\underline{NY}}\to\mathtt{Y}$. Thus, the answer is YES.

翻译中…

In the fourth test case, there are two possibilities for the first operation: $\mathtt{YY\underline{YN}Y}\to \mathtt{YYYY}$ or $\mathtt{YYY\underline{NY}}\to \mathtt{YYYY}$. However, in either case, it is not possible to perform any more operations without combining two $\mathtt{Y}$'s. Thus, the answer is NO.

翻译中…

In the fifth test case, the following is a valid sequence of operations: $\mathtt{N\underline{NN}NN}\to\mathtt{\underline{NN}NN}\to\mathtt{N\underline{NN}}\to\mathtt{\underline{NN}}\to\mathtt{N}$. Thus, the answer is YES.

翻译中…

样例

Input #1
7
YY
NN
NNY
YYYNY
NNNNN
YYYYYY
YNNNNN
Output #1
NO
YES
YES
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2178A
所属比赛
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。