Hyperdrome
Time limit2sMemory limit128 MB
Count substrings of S whose characters can be rearranged into a palindrome, where only the parity of each letter's count matters.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Prefix sum, Hash map, String
- Solved
- No attempts yet
Problem
A string is called a hyperdrome if its characters can be rearranged into a palindrome.
Given a string , count how many of its substrings are hyperdromes.
A substring of is the string formed by the -th through -th characters (). Two substrings with the same content but different are counted as different substrings.
A string is a palindrome if holds for every position .
consists of uppercase and lowercase letters ('a'–'z', 'A'–'Z'), and uppercase and lowercase letters are treated as different characters (for example, 'A' and 'a' are different).
Input
The first line contains the length of the string . ()
The second line contains the string .
Output
Print the number of substrings of that are hyperdromes.
Hint
A substring can be a hyperdrome even if it is not itself a palindrome. For example, 'aAA' is not a palindrome, but it can be rearranged into the palindrome 'AaA', so it is a hyperdrome.