Binary String
Time limit4sMemory limit2048 MB
For each k, count the 1s in T_k, where each ? copies the character k positions before it and leading ? positions become 0.
- Level
Medium6 of 10
- Topics
- Bit manipulation, String, Brute force
- Solved
- No attempts yet
Problem
You are given a string of length . Each character is one of 0, 1, or ?.
For every , define the string as follows. For each :
- If
?, then . - Otherwise, if , then
0. - Otherwise, . You can compute recursively to obtain .
The character set of is 01. For every , count the number of 1 characters in .
Input
The first line contains an integer (), the length of the string.
The second line contains the string of length . Each character is one of 0, 1, or ?.
Output
Print lines. The -th line contains the number of 1 characters in .