#P6273. [eJOI 2017] 魔法
[eJOI 2017] 魔法
Problem Description
Given a string of length . Let the number of distinct characters in be .
A substring of a string is any consecutive segment of that string.
A magic substring is defined as a non-empty substring of that satisfies: the number of distinct characters in this substring is , and the number of occurrences of each character is the same.
You need to find the number of different magic substrings of the given string .
If two substrings have different left or right endpoints, then they are considered different.
Input Format
The first line: an integer , the length of the string.
The second line: a string .
Output Format
Output one integer, the value of the answer .
8
abccbabc
4
7
abcABCC
1
20
SwSSSwwwwSwSwwSwwwwS
22
Hint
Sample Explanation
Sample 1 Explanation
- The substrings that satisfy the condition are: $\texttt{abc},\texttt{cba},\texttt{abc},\texttt{abccba}$.
Sample 2 Explanation
- Only the substring is a magic substring (case-sensitive, i.e. ).
Sample 3 Explanation
- One of them is .
Constraints
This problem uses bundled testdata, with 4 subtasks in total.
- Subtask 1 (10 points): .
- Subtask 2 (20 points): .
- Subtask 3 (30 points): (i.e. there are only two kinds of characters in ).
- Subtask 4 (40 points): no other limits.
For all testdata, it is guaranteed that , and the character set is $[\texttt{a},\texttt{z}] \cup [\texttt{A},\texttt{Z}]$.
Notes
The original problem is from: eJOI 2017 Problem A Magic.
Translation provided by: @_Wallace_.
Translated by ChatGPT 5