PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000158. Đếm đoạn có số A lớn hơn số B (Count Substrings With More A Than B)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn có số A lớn hơn số B (Count Substrings With More A Than B)
Count Substrings With More A Than B
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a string of length over A and B, count nonempty contiguous substrings containing strictly more occurrences of A than B. Substrings are identified by their endpoints, numbered from 1; distinct positions are counted separately.
Input
The first line contains integer . The second line contains the string of length .
Output
Print one integer: the number of qualifying substrings.
Subtasks
- Subtask 1 (20 points): ; ; all characters belong to
A,B. - Subtask 2 (30 points): ; ; all characters belong to
A. - Subtask 3 (50 points): ; ; all characters belong to
A,B.
Example 1
Input
3
AAB
Output
4
Explanation
The qualifying substrings are [1,1], [2,2], [1,2], [1,3]. Interval [2,3] has equal counts and is excluded.
Example 2
Input
3
BBB
Output
0
Explanation
No A occurs, so no interval qualifies.