cswork / OA打开练习工作台

AmazonOA #56

Special Strings (Binary Substrings)

估计困难可在线判题

考点(AI 标注)字符串前缀和区间位运算

Count the non-empty contiguous binary substrings in which the number of 0s is exactly the square of the number of 1s.

输入格式

A single line containing a binary string of length 1..100000.

输出格式

Output a single integer answer.

样例 1

输入:

010001

输出:

4

样例 2

输入:

0

输出:

0

样例 3

输入:

01

输出:

1

样例说明

Example 1: the two adjacent 01, the one adjacent 10, and the whole string (two 1s and four 0s) are valid, 4 in total. Example 2: with only 0s the condition cannot hold, so the answer is 0. Example 3: one 0 and one 1 satisfy 1=1², so the answer is 1.