Logo
(追記) (追記ここまで)

18986번 - Turn Off The Light 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB114250.000%

문제

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.

제한

예제 입력 1

3
3
000
3
111
8
01010101

예제 출력 1

0
26
432

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 4: Xi Lin Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /