#P1787. [入门赛 #22] 非众数 Hard Version
[入门赛 #22] 非众数 Hard Version
Background
This problem is the Hard Version of “Non-majority String”. Here . Thanks to
Problem Description
Given a string of length , where is guaranteed to contain only lowercase letters, find the number of non-empty substrings of that are non-majority strings.
Definition: non-empty substring
Let denote the -th character of (). Choose any two integers (), and take in the original order to form a new string. This new string is called a non-empty substring of .
For example, when , , , , and are all non-empty substrings of , while , , , and are not.
Definition: non-majority string
If, in a string , the maximum frequency among all characters is not greater than , then the string is called a non-majority string. Here denotes the greatest integer , and denotes the length of .
Input Format
One line containing a string .
Output Format
One line containing an integer, the answer.
aabb
2
fqmdfnc
21
Hint
Sample 1 Explanation
Among them, and are non-majority non-empty substrings.
Constraints
For of the testdata, , and the string consists of lowercase letters.
Translated by ChatGPT 5