当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6307:Turn Off The Light

题目描述
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.
输入解释
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$.
输出解释
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.
输入样例
3
3
000
3
111
8
01010101
输出样例
0
26
432
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6307

最后修改于 2020-10-25T23:30:09+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 32768/32768K(Java/Others)