#P9089. Sum of Meaningful Substring Values
Sum of Meaningful Substring Values
Sum of Meaningful Substring Values
You are given n strings consisting of lowercase letters. For each string, define its value as the number of its substrings that are meaningful. A substring is meaningful if and only if it can be segmented into one or more pieces, where each piece is a suffix of at least one of the n given strings. Note: If the same substring appears multiple times, count them separately.
A suffix of a string is a contiguous segment that starts at some position and extends to the end of the string. For example, if we have a string abc
, its suffixes are abc
, bc
, and c
.
Example:
Input: 4 int printf scanf ntnt</p>Explanation: For the string
printf
, the substringintf
is meaningful because it can be partitioned as "int" + "f", where "int" is a suffix ofint
and "f" is a suffix ofscanf
(orprintf
). However, the substringrint
is not meaningful.
The task is to compute the sum of the values of all n strings.
All formulas are represented in LaTeX. For example, the number of strings is denoted by \(n\), and a string's value is defined as the number of its meaningful substrings.
inputFormat
The first line contains an integer \(n\) denoting the number of strings. Following this, there are \(n\) lines, each containing one string consisting of lowercase letters.
For example:
4 int printf scanf ntnt
outputFormat
Output a single integer which is the sum of the values of the given \(n\) strings. That is, for each string, count the number of its substrings which can be segmented into one or more pieces, where each piece is a suffix (of any) given string, and then output the total sum.
sample
1
a
1
</p>