Turn Off The Light

TimeLimit:2000MS  MemoryLimit:32768KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
There are $n$ lights aligned in a row. These lights are numbered $1$ to $n$ from left to right. Initially some of the lights are turned on. Chiaki would like to turn off all the lights.
Chiaki starts from the $p$-th light. Each time she can go left or right (i.e. if Chiaki is at $x$, then she can go to $x-1$ or $x+1$) and then press the switch of the light in that position (i.e. if the light is turned on before, it will be turned off and vise versa).
For each $p=1,2,\dots,n$, Chiaki would like to know the minimum steps needed to turn off all the lights.
Input
There are multiple test cases. The first line of input is an integer $T$ indicates the number of test cases. For each test case:
The first line contains an integer $n$ ($2 \le n \le 10^6$) -- the number of lights.
The second line contains a binary string $s$ where $s_i=1$ means the $i$-th light is turned on and $s_i=0$ means $i$-th light is turned off.
It is guaranteed that the sum of all $n$ does not exceed $10^7$.
Output
For each test cases, output $(\sum\limits_{i=1}^{|s|} i \times z_i) \bmod (10^9+7)$, where $z_i$ is the number of step needed when Chikai starts at the $i$-th light.
SampleInput
3
3
000
3
111
8
01010101
SampleOutput
0
26
432
Submit
题目统计信息详细
总AC数3
通过人数2
尝试人数2
总提交量7
AC率28.57%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: