QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 512 MB Points totaux : 100

#7340. 首音互换

Statistiques

“Spoonerism”(得名于牛津大学牧师 William Archibald Spooner,他习惯于无意中创造这种词汇)是指一对单词,通过交换它们的开头,可以将它们变成另一对单词。例如,“blushing crow” 变成了 “crushing blow”。

给定一个单词列表,请从中找到一个 spoonerism。形式化地说:找到列表中的一对单词 $(A, B)$,它们可以分别拆分为 $A = pq$ 和 $B = rs$,使得单词 $C = rq$ 和 $D = ps$ 也出现在列表中。我们只允许真正的 spoonerism,即满足 $p \neq r$,$s \neq q$,且 $p, q, r, s$ 均非空。

输入格式

输入的第一行包含测试用例的数量 $z$。接下来是各测试用例的描述。

每个测试用例的第一行包含列表的长度 $n$ ($1 \le n \le 500\,000$)。接下来的 $n$ 行,每行包含一个由小写英文字母组成的单词。所有测试用例中单词的总长度不超过 $500\,000$。

输出格式

对于每个测试用例,如果没有找到 spoonerism,则输出一行 “NO”。如果存在 spoonerism,则输出一行 “YES”,接着输出一行包含单词 $A$ 和 $B$,再输出一行包含单词 $C$ 和 $D$。如果存在多个解,输出其中任意一个即可。你可以随意交换任意一行中单词的顺序。

样例

样例输入 1

1
9
blunder
blushing
crow
cry
crushing
blow
black
back
clap

样例输出 1

YES
blushing crow
crushing blow

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.