[Solution] Paranoid String Codeforces Solution
Let's call a binary string of length indexed from to paranoid if we can obtain a string of length by performing the following two kinds of operations times in any order :
- Select any substring of that is equal to 01, and then replace it with 1.
- Select any substring of that is equal to 10, and then replace it with 0.
For example, if 001, we can select the substring and perform the first operation. So we obtain 01.
You are given a binary string of length indexed from to . Find the number of pairs of
integers such that (the substring of from to ) is a paranoid string.
The first line contains an integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () — the size of .
The second line of each test case contains a binary string of characters . ( 0 or 1 for each )
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case, output the number of pairs of integers such that (the substring of from to ) is a paranoid string.
No comments:
Post a Comment