103102: [Atcoder]ABC310 C - Reversible

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

Description

Score : $300$ points

Problem Statement

There are $N$ sticks with several balls stuck onto them. Each ball has a lowercase English letter written on it.

For each $i = 1, 2, \ldots, N$, the letters written on the balls stuck onto the $i$-th stick are represented by a string $S_i$. Specifically, the number of balls stuck onto the $i$-th stick is the length $|S_i|$ of the string $S_i$, and $S_i$ is the sequence of letters on the balls starting from one end of the stick.

Two sticks are considered the same when the sequence of letters on the balls starting from one end of one stick is equal to the sequence of letters starting from one end of the other stick. More formally, for integers $i$ and $j$ between $1$ and $N$, inclusive, the $i$-th and $j$-th balls are considered the same if and only if $S_i$ equals $S_j$ or its reversal.

Print the number of different sticks among the $N$ sticks.

Constraints

  • $N$ is an integer.
  • $2 \leq N \leq 2 \times 10^5$
  • $S_i$ is a string consisting of lowercase English letters.
  • $|S_i| \geq 1$
  • $\sum_{i = 1}^N |S_i| \leq 2 \times 10^5$

Input

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

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

Output

Print the answer.


Sample Input 1

6
a
abc
de
cba
de
abc

Sample Output 1

3
  • $S_2$ = abc equals the reversal of $S_4$ = cba, so the second and fourth sticks are considered the same.
  • $S_2$ = abc equals $S_6$ = abc, so the second and sixth sticks are considered the same.
  • $S_3$ = de equals $S_5$ = de, so the third and fifth sticks are considered the same.

Therefore, there are three different sticks among the six: the first, second (same as the fourth and sixth), and third (same as the fifth).

Input

题意翻译

现在有 $N$ 个字符串,其中如果两个字符串相等或者翻转其中一个后相等,这两个字符串就是本质相同的,请你求出有多少个本质不同的字符串。

Output

分数:300分 部分 问题描述 有N根棍子,上面粘着一些球。每个球上都写有一个小写字母。 对于每个$i = 1, 2, \ldots, N$,粘在第$i$根棍子上的球上的字母用一个字符串$S_i$表示。 具体来说,粘在第$i$根棍子上的球的数量是字符串$S_i$的长度$|S_i|$,$S_i$是从棍子的一端开始的球上的字母序列。 当一根棍子从一端开始的球上的字母序列等于另一根棍子从一端开始的球上的字母序列时,认为这两根棍子是相同的。 更正式地说,对于1到N之间的整数$i$和$j$,第$i$根和第$j$根棍子被认为是相同的,当且仅当$S_i$等于$S_j$或其反转时。 打印出这$N$根棍子中有多少种不同的棍子。 部分 约束条件 * $N$是一个整数。 * $2 \leq N \leq 2 \times 10^5$ * $S_i$是由小写英文字母组成的字符串。 * $|S_i| \geq 1$ * $\sum_{i = 1}^N |S_i| \leq 2 \times 10^5$ 输入输出格式 输入格式 输入以以下格式从标准输入给出: $N$ $S_1$ $S_2$ $\vdots$ $S_N$ 输出格式 打印答案。 样例输入 1 6 a abc de cba de abc 样例输出 1 3 * $S_2$ = abc等于$S_4$ = cba的反转,所以第二根和第四根棍子被认为是相同的。 * $S_2$ = abc等于$S_6$ = abc,所以第二根和第六根棍子被认为是相同的。 * $S_3$ = de等于$S_5$ = de,所以第三根和第五根棍子被认为是相同的。 因此,六根棍子中有三根不同的:第一根,第二根(与第四根和第六根相同),以及第三根(与第五根相同)。

HINT

有多少个不同的字符串?正反向算相同的字符串哦?

加入题单

算法标签: