Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B"You are given a binary string s of length n . We define a maximal substring as a substring that cannot be extended while keeping all elements equal. For example, in the string 11000111 there are three maximal substrings: 11 , 000 and 111 . In one operation, you can select two maximal adjacent substrings. Since they are maximal and adjacent, it's easy to see their elements must have different values. Let a be the length of the sequence of ones and b be the length of the sequence of zeros. Then do the following: As an example, for 1110000 we make it 0000000 , for 0011 we make it 1111 . We call a string being good if it can be turned into 1111...1111 using the aforementioned operation any number of times (possibly, zero). Find the number of good substrings among all frac{n(n+1)}{2} non-empty substrings of s . Each test consists of multiple test cases. The first line contains a single integer t ( 1 <= q t <= q 10^5 ) -- the number of test cases. The description of test cases follows. The first line of each test case contains n ( 1 <= n <= 2 cdot 10^5 ) -- the length of the string s . The second line of each test case contains the binary string s of length n . It is guaranteed that sum of n across all test cases doesn't exceed 2 cdot 10^5 . For each test case, print a single integer -- the number of good substrings. Let's define a substring from index l to index r as [l, r] . For the first test case, the good substrings are: In the second test case, all substrings are good except [2,2] . In the third test case, all substrings are good. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
179717187 |
noob2004 |
H |
Nov. 6, 2022, 5:44 p.m. |
OK |
GNU C++17 |
TESTS |
56 |
592 |
84992000 |
|
|
179761892 |
JasonBrody0302 |
H |
Nov. 6, 2022, 6:15 p.m. |
OK |
GNU C++17 |
TESTS |
56 |
608 |
84992000 |
|
|
179823917 |
Benq |
H |
Nov. 6, 2022, 9:11 p.m. |
OK |
GNU C++17 (64) |
TESTS |
56 |
233 |
81612800 |
|
|
179840258 |
sabbirahmeds877 |
H |
Nov. 7, 2022, 2:24 a.m. |
OK |
GNU C++20 (64) |
TESTS |
56 |
265 |
81612800 |
|
|
179761219 |
NotLinux |
H |
Nov. 6, 2022, 6:08 p.m. |
OK |
GNU C++20 (64) |
TESTS |
56 |
529 |
101171200 |
|
|
179841674 |
SoKee_USTC |
H |
Nov. 7, 2022, 2:49 a.m. |
OK |
GNU C++20 (64) |
TESTS |
56 |
561 |
101171200 |
|
|
179838648 |
sabbirahmeds877 |
H |
Nov. 7, 2022, 1:50 a.m. |
OK |
GNU C++20 (64) |
TESTS |
56 |
561 |
101171200 |
|
|
remove filters
Back to search problems