MALD Contest 1 P5 - Scratch Cat and Desktop Backgrounds
View as PDF
The Scratch Cat wants to be a cool coder. He searches for some coding desktop backgrounds, which naturally always contain 1s and 0s. The Scratch Cat prefers specifically balanced text consisting of 1s and 0s. He defines the imbalance function of string as
, where
is the frequency of
1s, is the frequency of
0s, and is the length of string
. The function
represents the percentage of
that is extraneous.
The Scratch Cat determines the "coolness" of a background's text by the number of substrings of
that have an imbalance between
and
, inclusive. The Scratch Cat asks you for help because you are the true cool coder.
Constraints
Each character of is either
1 or 0.
Subtask 1 [10%]
Subtask 2 [40%]
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line will contain two space-separated integers and
, the minimum and maximum imbalance.
The second line will contain the string , the text in a desktop background.
only consists of
1 or 0.
Output Specification
Output the number of non-empty substrings with an imbalance in the range . Two substrings are distinct if they are from different segments of
, even if the substrings themselves are identical.
Do not round the function .
Sample Input
33 100
1001
Sample Output
7
Explanation
Below are the imbalances for all substrings of 1001:
:
1100
:
100
:
0100
:
10033.33...
:
00100
:
0100
:
10010
:
00133.33...
:
010
:
1100
substrings have an imbalance between
and
.
Comments