#P3370. 【模板】字符串哈希

【模板】字符串哈希

Description

As stated, given NN strings (the length of the ii-th string is MiM_i, and each string contains digits and letters in both cases; it is case-sensitive), find how many distinct strings there are among the NN strings.

Friendly reminder: if you really want to practice hashing seriously, please be self-disciplined.

Input Format

The first line contains an integer NN, the number of strings.

The next NN lines each contain one string, the provided strings.

Output Format

Output one line containing one integer, the number of distinct strings.

5
abc
aaaa
abc
abcc
12345
4

Hint

Constraints

For 30%30\% of the testdata: N10N \leq 10, Mi6M_i \approx 6, Mmax15M_{\max} \leq 15.

For 70%70\% of the testdata: N1000N \leq 1000, Mi100M_i \approx 100, Mmax150M_{\max} \leq 150.

For 100%100\% of the testdata: N10000N \leq 10000, Mi1000M_i \approx 1000, Mmax1500M_{\max} \leq 1500.

Sample Explanation

In the sample, the first string abc\tt{abc} and the third string abc\tt{abc} are the same, so the set of provided strings is {aaaa,abc,abcc,12345}\{\tt{aaaa}, \tt{abc}, \tt{abcc}, \tt{12345}\}, hence there are 44 distinct strings.

Further Reading

The following problems reflect the correctness analysis of string hashing from different aspects.

Translated by ChatGPT 5