#PS0000151. Đếm xâu con kỳ diệu (Number of Wonderful Substrings)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm xâu con kỳ diệu (Number of Wonderful Substrings)
Number of Wonderful Substrings
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given a string over the letters a through j, count its nonempty contiguous substrings in which at most one distinct letter occurs an odd number of times. All other letters occur an even number of times, possibly zero. Count different pairs of endpoints separately even when their contents match.
Input
One line containing the string of length .
Output
Print the number of qualifying intervals as one integer.
Subtasks
- Subtask 1 (20 points): ; ; the characters of belong to
abcdefghij. - Subtask 2 (30 points): ; ; the characters of belong to
ab. - Subtask 3 (50 points): ; ; the characters of belong to
abcdefghij.
Example 1
Input
aba
Output
4
Explanation
The three single-character intervals and [1,3] (aba) qualify. Both length-two intervals have two odd counts. The total is 4.
Example 2
Input
aabb
Output
9
Explanation
Four length-one, two length-two (aa, bb), two length-three (aab, abb), and the entire string qualify. Only [2,3] fails.
Example 3
Input
he
Output
2
Explanation
Both single-character intervals qualify; he has two odd counts.