103071: [Atcoder]ABC307 B - racecar

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:7 Solved:0

Description

Score : $200$ points

Problem Statement

You are given $N$ strings $S_1,S_2,\ldots,S_N$ consisting of lowercase English letters.
Determine if there are distinct integers $i$ and $j$ between $1$ and $N$, inclusive, such that the concatenation of $S_i$ and $S_j$ in this order is a palindrome.

A string $T$ of length $M$ is a palindrome if and only if the $i$-th character and the $(M+1-i)$-th character of $T$ are the same for every $1\leq i\leq M$.

Constraints

  • $2\leq N\leq 100$
  • $1\leq \lvert S_i\rvert \leq 50$
  • $N$ is an integer.
  • $S_i$ is a string consisting of lowercase English letters.
  • All $S_i$ are distinct.

Input

The input is given from Standard Input in the following format:

$N$
$S_1$
$S_2$
$\vdots$
$S_N$

Output

If there are $i$ and $j$ that satisfy the condition in the problem statement, print Yes; otherwise, print No.


Sample Input 1

5
ab
ccef
da
a
fe

Sample Output 1

Yes

If we take $(i,j)=(1,4)$, the concatenation of $S_1=$ab and $S_4=$a in this order is aba, which is a palindrome, satisfying the condition.
Thus, print Yes.

Here, we can also take $(i,j)=(5,2)$, for which the concatenation of $S_5=$fe and $S_2=$ccef in this order is feccef, satisfying the condition.


Sample Input 2

3
a
b
aba

Sample Output 2

No

No two distinct strings among $S_1$, $S_2$, and $S_3$ form a palindrome when concatenated. Thus, print No.
Note that the $i$ and $j$ in the statement must be distinct.


Sample Input 3

2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Output 3

Yes

Input

题意翻译

给出 $N$ 个仅由小写字母组成的字符串 $S_1, S_2, S_3, \cdots, S_N$。 问在 $1$ 和 $N$ 之间(包括 $1$ 和 $N$)是否存在两个不同的整数 $i$ 和 $j$,使得 $S_i$ 和 $S_j$ 按 $S_i + S_j$ 的顺序串联起来是一个回文串。若存在则输出 `Yes` ,否则输出 `No` 。 长度为 $M$ 的字符串 $T$ 是回文串,当且仅当 $T$ 的第 $i(1 \leqslant i \leqslant M)$ 个字符和第 $(M + 1 - i)$ 个字符是相同的。

Output

分数:200分

问题描述

给你 $N$ 个由小写英文字母组成的字符串 $S_1,S_2,\ldots,S_N$。
确定是否存在两个在 1 到 $N$(包括 1 和 $N$)之间的 不同 整数 $i$ 和 $j$,使得将 $S_i$ 和 $S_j$ 按此顺序连接后是一个回文串。

长度为 $M$ 的字符串 $T$ 是一个回文串,当且仅当 $T$ 的第 $i$ 个字符和第 $(M+1-i)$ 个字符对于每一个 $1\leq i\leq M$ 都相同。

约束条件

  • $2\leq N\leq 100$
  • $1\leq \lvert S_i\rvert \leq 50$
  • $N$ 是一个整数。
  • $S_i$ 是由小写英文字母组成的字符串。
  • 所有的 $S_i$ 都是不同的。

输入

输入从标准输入按以下格式给出:

$N$
$S_1$
$S_2$
$\vdots$
$S_N$

输出

如果存在满足问题描述中的条件的 $i$ 和 $j$,则打印 Yes;否则,打印 No


样例输入 1

5
ab
ccef
da
a
fe

样例输出 1

Yes

如果我们取 $(i,j)=(1,4)$,则将 $S_1=$ab 和 $S_4=$a 按此顺序连接得到 aba,这是一个回文串,满足条件。
因此,打印 Yes。 这里,我们还可以取 $(i,j)=(5,2)$,对于该取值,将 $S_5=$fe 和 $S_2=$ccef 按此顺序连接得到 feccef,也满足条件。


样例输入 2

3
a
b
aba

样例输出 2

No

将 $S_1$、$S_2$ 和 $S_3$ 中的任意两个不同的字符串连接时,都不会得到一个回文串。 因此,打印 No。 注意,问题描述中的 $i$ 和 $j$ 必须不同。


样例输入 3

2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

样例输出 3

Yes

HINT

n个字符串,是否能找出两个拼接在一起,形成回文串?

加入题单

算法标签: