CF1913B.Swap and Delete

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a binary string ss (a string consisting only of 0-s and 1-s).

You can perform two types of operations on ss :

  1. delete one character from ss . This operation costs 11 coin;
  2. swap any pair of characters in ss . This operation is free (costs 00 coins).

You can perform these operations any number of times and in any order.

Let's name a string you've got after performing operations above as tt . The string tt is good if for each ii from 11 to t|t| tisit_i \neq s_i ( t|t| is the length of the string tt ). The empty string is always good. Note that you are comparing the resulting string tt with the initial string ss .

What is the minimum total cost to make the string tt good?

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. Then tt test cases follow.

The only line of each test case contains a binary string ss ( 1s21051 \le |s| \le 2 \cdot 10^5 ; si{s_i \in \{ 0, 1 }\} ) — the initial string, consisting of characters 0 and/or 1.

Additional constraint on the input: the total length of all strings ss doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print one integer — the minimum total cost to make string tt good.

输入输出样例

  • 输入#1

    4
    0
    011
    0101110001
    111100

    输出#1

    1
    1
    0
    4

说明/提示

In the first test case, you have to delete a character from ss to get the empty string tt . Only then tt becomes good. One deletion costs 11 coin.

In the second test case, you can, for example, delete the second character from ss to get the string 01, and then swap the first and second characters to get the string tt == 10. String tt is good, since t1s1t_1 \neq s_1 and t2s2t_2 \neq s_2 . The total cost is 11 coin.

In the third test case, you can, for example, swap s1s_1 with s2s_2 , swap s3s_3 with s4s_4 , swap s5s_5 with s7s_7 , s6s_6 with s8s_8 and s9s_9 with s10s_{10} . You'll get tt == 1010001110. All swap operations are free, so the total cost is 00 .

首页