Problem 2591 --Turn Off The Light

2591: Turn Off The Light

"
Time Limit $2$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
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,…,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≤n≤106) -- the number of lights.
The second line contains a binary string s where si=1 means the i-th light is turned on and si=0 means i-th light is turned off.
It is guaranteed that the sum of all n does not exceed 107.
For each test cases, output (∑i=1|s|i×zi)mod(109+7), where zi is the number of step needed when Chikai starts at the i-th light.
3
3
000
3
111
8
01010101
0
26
432

推荐代码 查看2591 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$1397 $ms] 淡意的温柔 606329 2020-07-09 15:30:52
内存最少[$0 $KB] 淡意的温柔 606329 2020-07-09 15:30:52
第一AC 淡意的温柔 606329 2020-07-09 15:30:52
第一挑战 淡意的温柔 606329 2020-07-09 15:30:52

赛题来源/所属竞赛 HDU N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛