F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Turn Off The Light

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 321    Accepted Submission(s): 98


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.
 

Sample Input
3 3 000 3 111 8 01010101
 

Sample Output
0 26 432
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 12:15:43, Gzip enabled