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

31142번 - PTSD 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB655100.000%

문제

There are $n$ soldiers in JB kingdom, numbered as 1,ドル 2, \cdots, n$. The $i$-th soldier has a power value of $i$.

There is a tournament in the kingdom now. The soldiers need to be divided into several groups where each soldier belongs to exactly one group. Note that it's allowed for a group to contain only one single soldier. For some unknown reason, some soldiers have a disease called PTSD (post-traumatic stress disorder). The soldiers with PTSD don't like being the $second$ strongest soldier in their groups. Formally speaking, a soldier with PTSD will be upset if there is exactly one other soldier with a larger power value than him in his group.

JB, the king of JB kingdom, wants to maximize the sum of the power values of the soldiers who feel upset because of PTSD. You are asked to help him divide the soldiers.

입력

There are multiple test cases. The first line of the input contains a positive integer $T,ドル indicating the number of test cases. For each test case:

The first line contains an integer $n$ (1ドル \le n \le 10^6$), indicating the number of soldiers.

The second line contains a string $s$ of length $n$. It's guaranteed that $s$ only contains '0' and '1'. The $i$-th character describes the $i$-th soldier: If $s_i = $ '1', the $i$-th soldier has PTSD. Otherwise, the $i$-th soldier doesn't have PTSD.

It's guaranteed that the sum of $n$ of all test cases doesn't exceed 10ドル^6$.

출력

For each test case, output one line containing an integer, indicating the maximum sum of power values of the upset soldiers.

제한

예제 입력 1

4
5
10101
8
11111111
4
1100
4
0110

예제 출력 1

4
16
3
3

노트

For the first test case, a valid division is [1, 2], [3, 4], [5], which makes the 1ドル$-st soldier and the 3ドル$-rd soldier upset. [1, 2], [3, 5], [4] is also valid.

For the second test case, a valid division is [1, 2], [3, 4], [5, 6], [7, 8].

For the third test case, a valid division is [1, 3], [2, 4].

For the fourth test case, a valid division is [1, 2, 3, 4].

출처

Contest > Open Cup > 2021/2022 Season > Stage 6: Grand Prix of EDG I번

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

출처

대학교 대회

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

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