欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1658A.Marin and Photoshoot
Marin and Photoshoot
Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!
For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least cosplayers, the number of males does not exceed the number of females (obviously).
Currently, the line has cosplayers which can be described by a binary string . The -th cosplayer is male if and female if . To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.
Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a positive integer () — the number of cosplayers in the initial line.
The second line of each test case contains a binary string of length — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female.
Note that there is no limit on the sum of .
Output
For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.
Note
In the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, .
In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, .
Samples
9
3
000
3
001
3
010
3
011
3
100
3
101
3
110
3
111
19
1010110000100000101
4
2
1
0
2
0
0
0
17
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |