CF1620A.Equal or Not Equal

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You had nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n arranged in a circle. For each pair of neighboring numbers (a1a_1 and a2a_2, a2a_2 and a3a_3, ..., an−1a_{n - 1} and ana_n, and ana_n and a1a_1), you wrote down: are the numbers in the pair equal or not.

Unfortunately, you've lost a piece of paper with the array aa. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array aa which is consistent with information you have about equality or non-equality of corresponding pairs?

你有 nn 个正整数 a1,a2,…,ana_1, a_2, \dots, a_n,它们按环形排列。对于每一对相邻的数(即 a1a_1 与 a2a_2、a2a_2 与 a3a_3、……、an−1a_{n - 1} 与 ana_n,以及 ana_n 与 a1a_1),你记录下了:该对中的两个数是否相等。

不幸的是,你丢失了写有数组 aa 的那张纸。此外,你还担心关于相邻元素是否相等的信息本身可能存在矛盾。因此,你开始思考:是否存在某个数组 aa,使得它与你所掌握的关于各相邻数对是否相等(或不相等)的信息完全一致?

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Next tt cases follow.

The first and only line of each test case contains a non-empty string ss consisting of characters E and/or N. The length of ss is equal to the size of array nn and 2≤n≤502 \le n \le 50. For each ii from 11 to nn:

  • if si=s_i = E then aia_i is equal to ai+1a_{i + 1} (an=a1a_n = a_1 for i=ni = n);
  • if si=s_i = N then aia_i is not equal to ai+1a_{i + 1} (an≠a1a_n \neq a_1 for i=ni = n).

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。接下来是 tt 个测试用例。

每个测试用例仅有一行,包含一个非空字符串 ss,其字符仅由 E 和/或 N 组成。字符串 ss 的长度等于数组 nn 的大小,且满足 2≤n≤502 \le n \le 50。对于每个从 11 到 nn 的 ii:

  • 若 si=s_i = E,则 ai=ai+1a_i = a_{i + 1}(当 i=ni = n 时,规定 an=a1a_n = a_1);
  • 若 si=s_i = N,则 ai≠ai+1a_i \neq a_{i + 1}(当 i=ni = n 时,规定 an≠a1a_n \neq a_1)。

输出格式

For each test case, print YES if it's possible to choose array aa that are consistent with information from ss you know. Otherwise, print NO.

It can be proved, that if there exists some array aa, then there exists an array aa of positive integers with values less or equal to 10910^9.

对于每个测试用例,如果能够选择一个与已知信息 ss 一致的数组 aa,则输出 YES;否则输出 NO。

可以证明:若存在某个数组 aa,则必存在一个由不超过 10910^9 的正整数组成的数组 aa。

输入输出样例

  • 输入#1

    4
    EEE
    EN
    ENNEENE
    NENN

    输出#1

    YES
    NO
    YES
    YES

说明/提示

In the first test case, you can choose, for example, a1=a2=a3=5a_1 = a_2 = a_3 = 5.

In the second test case, there is no array aa, since, according to s1s_1, a1a_1 is equal to a2a_2, but, according to s2s_2, a2a_2 is not equal to a1a_1.

In the third test case, you can, for example, choose array a=[20,20,4,50,50,50,20]a = [20, 20, 4, 50, 50, 50, 20].

In the fourth test case, you can, for example, choose a=[1,3,3,7]a = [1, 3, 3, 7].

在第一个测试用例中,你可以选择,例如,a1=a2=a3=5a_1 = a_2 = a_3 = 5。

在第二个测试用例中,不存在满足条件的数组 aa,因为根据 s1s_1,a1a_1 等于 a2a_2,但根据 s2s_2,a2a_2 不等于 a1a_1。

在第三个测试用例中,你可以选择,例如,数组 a=[20,20,4,50,50,50,20]a = [20, 20, 4, 50, 50, 50, 20]。

在第四个测试用例中,你可以选择,例如,a=[1,3,3,7]a = [1, 3, 3, 7]。

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

首页