CF1397A.Juggling Letters

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn strings s1,s2,…,sns_1, s_2, \ldots, s_n consisting of lowercase Latin letters.

In one operation you can remove a character from a string sis_i and insert it to an arbitrary position in a string sjs_j (jj may be equal to ii). You may perform this operation any number of times. Is it possible to make all nn strings equal?

给你 nn 个字符串 s1,s2,…,sns_1, s_2, \ldots, s_n,每个字符串均由小写拉丁字母组成。

在一次操作中,你可以从字符串 sis_i 中移除一个字符,并将其插入到字符串 sjs_j 的任意位置(jj 可以等于 ii)。你可以执行该操作任意多次。是否可能使所有 nn 个字符串变得完全相同?

输入格式

The first line contains tt (1≤t≤101 \le t \le 10): the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤10001 \le n \le 1000): the number of strings.

nn lines follow, the ii-th line contains sis_i (1≤∣si∣≤10001 \le \lvert s_i \rvert \le 1000).

The sum of lengths of all strings in all test cases does not exceed 10001000.

第一行包含一个整数 tt(1≤t≤101 \le t \le 10):测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤10001 \le n \le 1000):字符串的数量。

接下来 nn 行,第 ii 行包含字符串 sis_i(1≤∣si∣≤10001 \le \lvert s_i \rvert \le 1000)。

所有测试用例中所有字符串的长度总和不超过 10001000。

输出格式

If it is possible to make the strings equal, print "YES" (without quotes).

Otherwise, print "NO" (without quotes).

You can output each character in either lowercase or uppercase.

如果可以使两个字符串相等,则输出 "YES"(不带引号)。

否则,输出 "NO"(不带引号)。

每个字符可以以小写或大写形式输出。

输入输出样例

  • 输入#1

    4
    2
    caa
    cbb
    3
    cba
    cba
    cbb
    4
    ccab
    cbac
    bca
    acbcc
    4
    acb
    caf
    c
    cbafc

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, you can do the following:

  • Remove the third character of the first string and insert it after the second character of the second string, making the two strings "ca" and "cbab" respectively.
  • Remove the second character of the second string and insert it after the second character of the first string, making both strings equal to "cab".

In the second test case, it is impossible to make all nn strings equal.

在第一个测试用例中,你可以执行以下操作:

  • 删除第一个字符串的第三个字符,并将其插入到第二个字符串的第二个字符之后,使两个字符串分别变为 "ca" 和 "cbab"。
  • 删除第二个字符串的第二个字符,并将其插入到第一个字符串的第二个字符之后,使两个字符串均变为 "cab"。

在第二个测试用例中,无法使所有 nn 个字符串相等。

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

首页