CF1430D.String Deletion
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a string s consisting of n characters. Each character is either 0 or 1.
You can perform operations on the string. Each operation consists of two steps:
- select an integer i from 1 to the length of the string s , then delete the character si (the string length gets reduced by 1 , the indices of characters to the right of the deleted one also get reduced by 1 );
- if the string s is not empty, delete the maximum length prefix consisting of the same characters (the indices of the remaining characters and the string length get reduced by the length of the deleted prefix).
Note that both steps are mandatory in each operation, and their order cannot be changed.
For example, if you have a string s= 111010, the first operation can be one of the following:
- select i=1 : we'll get 111010 → 11010 → 010;
- select i=2 : we'll get 111010 → 11010 → 010;
- select i=3 : we'll get 111010 → 11010 → 010;
- select i=4 : we'll get 111010 → 11110 → 0;
- select i=5 : we'll get 111010 → 11100 → 00;
- select i=6 : we'll get 111010 → 11101 → 01.
You finish performing operations when the string s becomes empty. What is the maximum number of operations you can perform?
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
The first line of each test case contains a single integer n ( 1≤n≤2⋅105 ) — the length of the string s .
The second line contains string s of n characters. Each character is either 0 or 1.
It's guaranteed that the total sum of n over test cases doesn't exceed 2⋅105 .
输出格式
For each test case, print a single integer — the maximum number of operations you can perform.
输入输出样例
输入#1
5 6 111010 1 0 1 1 2 11 6 101010
输出#1
3 1 1 1 3
说明/提示
In the first test case, you can, for example, select i=2 and get string 010 after the first operation. After that, you can select i=3 and get string 1. Finally, you can only select i=1 and get empty string.