report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Compare string - FlandreOJ: Flandre Online Judge

Compare string

Time limit: 1000 ms
Memory limit: 256 MB
Given a function $f(s, t)$ which takes two string $s$ and $t$ as input. Without loss of generality that $|s| \le |t|$, let's say the output of the function is as follow: $$ \begin{equation} f(s, t)=\begin{cases} 0, & \text{if $s$ is a prefix of $t$}.\\\\ \text{the first position where $s$ and $t$ differ}, & \text{otherwise}. \end{cases} \end{equation} $$ For example, $f(\text{abc}, \text{abd}) = 3$. Given a $n$ string $S_i$. Calculate: $$ \sum_{i=1}^{n} \sum_{j=i+1}^{n} f(S_i,S_j) $$ ### Input - The first line contains an integer $n$. - The next $n$ lines, each line contains a string $S_i$, each string contains only lowercase letters. ### Output - Print the value. ### Constraints - $1 \le n \le 10^5$. - $1 \le \sum{|S_i|} \le 10^6$ ### Example Input: ``` 4 cat hat mat sir ``` Output: ``` 6 ```
Introduction to Trie
Prefix
Compare string
Maximum score
Report
Maximum XOR subarray
Query on string
Language
Poem
Palindrome pairs
Mass XOR queries
XOR-path on tree
The ancient book
Topic
Data structure
String
Rating 1300
Solution (1) Solution