#abc307b. B - racecar

B - racecar

Score : 200200 points

问题描述

你已知 NN 个由小写英文字母组成的字符串 S1,S2,,SNS_1,S_2,\ldots,S_N
判断是否存在 不同的 整数 iijj,满足 1i,jN1\leq i,j\leq N(包含两端点),使得按顺序拼接的 SiS_iSjS_j 构成一个回文串。

若长度为 MM 的字符串 TT 满足对于所有 1iM1\leq i\leq M,其第 ii 个字符与第 (M+1i)(M+1-i) 个字符相同,则称该字符串 TT 是回文串。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given NN strings S1,S2,,SNS_1,S_2,\ldots,S_N consisting of lowercase English letters.
Determine if there are distinct integers ii and jj between 11 and NN, inclusive, such that the concatenation of SiS_i and SjS_j in this order is a palindrome.

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

Constraints

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

Input

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

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

If there are ii and jj 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)(i,j)=(1,4), the concatenation of S1=S_1=ab and S4=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)(i,j)=(5,2), for which the concatenation of S5=S_5=fe and S2=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 S1S_1, S2S_2, and S3S_3 form a palindrome when concatenated. Thus, print No.
Note that the ii and jj in the statement must be distinct.

Sample Input 3

2
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Output 3

Yes

update @ 2024/3/10 08:40:40