report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Balance substring - MarisaOJ: Marisa Online Judge

Balance substring

Time limit: 1000 ms
Memory limit: 256 MB
You are given a binary string $S$. Count the number of non-empty substrings where the number of $0$ is equal to the number of $1$. A substring is a consecutive sequence of characters within a string. For example, given the string `marisa`, `ris` is a substring, but `rsa` is not. ### Input - The first line contains string $S$. ### Output - Print 1 integers, the number of sastified substrings. ### Constraints - $1 \le |S| \le 10^5$. ### Example Input: ``` 10010 ``` Output: ``` 4 ```
Introduction to Prefix sum
Prefix sum
Maximum subarray sum
Balance substring
Divisible by d
Subarray sum
Game on array
2D prefix sum
Stair query
Maximum sum subarray 2
Average
Ratio Substrings
Maximum submatrix sum
Maximum subarray sum 3
Manhattan distance
Minimum distance
Topic
Prefix sum
Rating 800
Solution (1) Solution