Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Nobita and Shizuka

By iammarajul · Limits 1s, 512 MB

Probably, You all Know About The Famous Japanese Cartoon Character Nobita and Shizuka. Nobita Shizuka are very Good friend. However , Shizuka Love a special kind of string Called Tokushuna.

A string $T$ is called Tokushuna if

  • The length of the string is greater or equal than 3 ($|T| ≥ 3$)
  • It starts and ends with a charecter $\texttt{1}$ (one)
  • It contains ($|T|-2$) number of $\texttt{0}$ (zero)

Here $|T|$ is the length of string $T$.

For example, $\texttt{10001}$, $\texttt{101}$, and $\texttt{10001}$ is Tokushuna string. But, $\texttt{1100}$, $\texttt{1111}$, and $\texttt{0000}$ are not.

One day Shizuka gave a problem to Nobita and promised to go on a date with him if he was able to solve the problem. Shizuka gave a string $S$ and asked him to count the number of Tokushuna strings that can be found from all possible substrings of string S. Nobita wants to go on a date with Shizuka but you know he is very weak in maths and counting. And in this time Doraemon is not present to help him. So he needs your help to solve the problem .


In the first line of the input there is an integer $T$, the number of test cases. In each test case, you are given a binary string $S$ consisting of only $\texttt{0}$ and $\texttt{1}$.

Subtask 1 (50 Points)

$1 ≤ T ≤ 100$, $1 ≤ |S| ≤ 100$

Subtask 2 (50 points)

$1 ≤ T ≤ 100$, $1 ≤ |S| ≤ 10<sup>5$


For each test case output a line $\texttt{Case X: Y}$ where $X$ is the case number and $Y$ is the number of Tokushuna string can be found from all possible the substring of string $S$.


Case 1: 1
Case 2: 2
Case 3: 3

In the first case $\texttt{10001}$ is itself is a Tokushuna string. In the second case there are 2 substrings (S[1:3] 101 and S[3:6]) that are $\texttt{101}$ that are Tokushuna string.



78% Solution Ratio

prodip_bsmrstuEarliest, 1M ago

iammarajulFastest, 0.0s

Aimon026Lightest, 0 B

aNkanpy.pritomShortest, 99B


Login to submit


Subtask 1: Generate all possible substrings and count the number of Tokushuna substrings. The compl...