欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1913B.Swap and Delete
Swap and Delete
You are given a binary string (a string consisting only of 0-s and 1-s).
You can perform two types of operations on :
- delete one character from . This operation costs coin;
- swap any pair of characters in . This operation is free (costs 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 . The string is good if for each from to ( is the length of the string ). The empty string is always good. Note that you are comparing the resulting string with the initial string .
What is the minimum total cost to make the string good?
Input
The first line contains a single integer () — the number of test cases. Then test cases follow.
The only line of each test case contains a binary string (; 0, 1) — the initial string, consisting of characters 0 and/or 1.
Additional constraint on the input: the total length of all strings doesn't exceed .
Output
For each test case, print one integer — the minimum total cost to make string good.
Note
In the first test case, you have to delete a character from to get the empty string . Only then becomes good. One deletion costs coin.
In the second test case, you can, for example, delete the second character from to get the string 01, and then swap the first and second characters to get the string 10. String is good, since and . The total cost is coin.
In the third test case, you can, for example, swap with , swap with , swap with , with and with . You'll get 1010001110. All swap operations are free, so the total cost is .
Samples
4
0
011
0101110001
111100
1
1
0
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |