Logo
(追記) (追記ここまで)

33431번 - Period of a String 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB64360.000%

문제

Randias has $n$ strings $s_{1}, s_{2}, \ldots, s_{n}$.

For two strings $a = \overline{a_{0} a_{1} \ldots a_{p-1}}$ and $b = \overline{b_{0} b_{1} \ldots b_{q-1}},ドル if for all $i$ (0ドル \le i < q$), $b_{i} = a_{i \bmod {p}},ドル we say that $a$ is a period of $b$.

Now, Randias can perform the following operation:

  • Choose one string $s_{i}$ and choose two indices $j$ and $k$ (0ドル \le j, k < |s_{i}|$), then swap $s_{i,j}$ and $s_{i,k}$.

He can perform this operation any number of times. After all the operations, he wants the following to be true: for each 1ドル < i \le n,ドル string $s_{i-1}$ is a period of $s_{i}$.

Help him to find the possible final strings, or determine it is impossible.

입력

Each test contains multiple test cases. The first line contains a single integer $t$ (1ドル \le t \le 10^4$) denoting the number of test cases. For each test case:

The first line contains a single integer $n$ (2ドル \le n \le 10^5$).

Then follow $n$ lines. The $i$-th of these lines contains the string $s_{i}$ (1ドル \le |s_{i}| \le 5 \cdot 10^6$). It is guaranteed that the strings only contain lowercase English letters.

It is guaranteed that the sum of $n$ does not exceed 10ドル^5,ドル and the sum of $|s_{i}|$ does not exceed 5ドル \cdot 10^6$.

출력

For each test case, if it is possible to make $s_{i-1}$ a period of $s_{i}$ for all $i$ after some operations, output "YES" (without quotes) on the first line. Then output $n$ strings in $n$ lines. The $i$-th string $s'_{i}$ represents the $i$-th string after all operations. If there are multiple answers, output any one of them.

If it is impossible to do that, output "NO" (without quotes) on the first line.

제한

예제 입력 1

4
2
abc
abcd
4
bbcaa
cabb
acabbbb
a
3
ab
aab
bbaaaaab
3
ab
aab
bbaaaaaa

예제 출력 1

NO
YES
abbca
abbc
abbcabb
a
YES
ab
aba
abaabaab
NO

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2024 > Day 3: ZJU Contest E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /