CF2178A.Yes or Yes

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

You can repeatedly apply the following operation on ss:

  • Choose any two adjacent characters and replace them with their logical OR.

Formally, in each operation, you can choose an index ii (1≤i≤∣s∣−11 \leq i \leq |s|-1), remove the characters sis_i and si+1s_{i+1}, then insert:

  • A single Y\mathtt{Y} if at least one of sis_i or si+1s_{i+1} is Y\mathtt{Y};
  • A single N\mathtt{N} if both sis_i and si+1s_{i+1} are N\mathtt{N}.

Note that after each operation, the length of ss decreases by 11.

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 ss to a single character by repeatedly applying the operation above, without ever combining two Y\mathtt{Y}'s.

去年圣诞节,你的朋友费尔南多送给你一个仅由字符 Y\mathtt{Y} 和 N\mathtt{N} 组成的字符串 ss,分别代表“是(Yes)”和“否(No)”。

你可以对 ss 重复执行以下操作:

形式化地说,每次操作中,你可以选择一个下标 ii(满足 1≤i≤∣s∣−11 \leq i \leq |s|-1),删除字符 sis_i 和 si+1s_{i+1},然后插入:

  • 单个 Y\mathtt{Y},如果 sis_i 或 si+1s_{i+1} 中至少有一个是 Y\mathtt{Y};
  • 单个 N\mathtt{N},如果 sis_i 和 si+1s_{i+1} 均为 N\mathtt{N}。

注意:每次操作后,字符串 ss 的长度减少 11。

不幸的是,费尔南多不希望你将两个 Y\mathtt{Y} 进行组合(即执行“是 OR 是”),因为他曾因某首特定歌曲而遭受过心理创伤。

请判断:能否通过反复执行上述操作,将 ss 化简为单个字符,且在过程中从未将两个 Y\mathtt{Y} 组合在一起?

输入格式

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

The only line of each test case contains the string ss (2≤∣s∣≤1002\le |s|\le 100). It is guaranteed that si=Ys_i = \mathtt{Y} or N\mathtt{N}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤5001 \le t \le 500)。随后是测试用例的描述。

每个测试用例仅有一行,包含字符串 ss(2≤∣s∣≤1002\le |s|\le 100)。保证字符串中每个字符 sis_i 为 Y\mathtt{Y} 或 N\mathtt{N}。

输出格式

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.

对于每个测试用例,如果该字符串能通过重复应用上述操作缩减为单个字符,则输出 “YES”;否则输出 “NO”。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均被视为肯定回答。

输入输出样例

  • 输入#1

    7
    YY
    NN
    NNY
    YYYNY
    NNNNN
    YYYYYY
    YNNNNN

    输出#1

    NO
    YES
    YES
    NO
    YES
    NO
    YES

说明/提示

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

In the third test case, the following is a valid sequence of operations: NN‾Y→NY‾→Y\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: YYYN‾Y→YYYY\mathtt{YY\underline{YN}Y}\to \mathtt{YYYY} or YYYNY‾→YYYY\mathtt{YYY\underline{NY}}\to \mathtt{YYYY}. However, in either case, it is not possible to perform any more operations without combining two Y\mathtt{Y}'s. Thus, the answer is NO.

In the fifth test case, the following is a valid sequence of operations: NNN‾NN→NN‾NN→NNN‾→NN‾→N\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.

在第一个测试用例中,你无法合并 s1s_1 和 s2s_2,因为它们均为 Y\mathtt{Y}。因此,答案为 NO。

在第三个测试用例中,以下是一组合法的操作序列:NN‾Y→NY‾→Y\mathtt{\underline{NN}Y}\to\mathtt{\underline{NY}}\to\mathtt{Y}。因此,答案为 YES。

在第四个测试用例中,第一次操作有两种可能:YYYN‾Y→YYYY\mathtt{YY\underline{YN}Y}\to \mathtt{YYYY} 或 YYYNY‾→YYYY\mathtt{YYY\underline{NY}}\to \mathtt{YYYY}。然而,无论哪种情况,后续都无法再执行任何操作而不合并两个 Y\mathtt{Y}。因此,答案为 NO。

在第五个测试用例中,以下是一组合法的操作序列:NNN‾NN→NN‾NN→NNN‾→NN‾→N\mathtt{N\underline{NN}NN}\to\mathtt{\underline{NN}NN}\to\mathtt{N\underline{NN}}\to\mathtt{\underline{NN}}\to\mathtt{N}。因此,答案为 YES。

输入解题思路,AI测评打分。不知道怎么写?

首页