CF1955E.Long Inversions
普及+/提高
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
给定一个长度为$ n 的01字符串 s $。01字符串是指只包含字符'1' 和'0'的字符串
可以选定一个整数$ k $ ( $ 1 \le k \le n $ ),将字符串中的连续k个字符进行替换,将0替换成1,1替换成0。
当 $ n=5 $ , $ s=00100 时,你可以指定 k=3 $ ,做如下操作:
- 翻转1-3的子串:$ s=\color{blue}{110}00 $ ;
- 反转3-5的子串:$ s=11\color{blue}{111} $ ;
经过不限次操作后,寻找能将01字符串中的所有字符转换成1的最大$ k $值。
输入格式
The first line contains an integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases.
The first line of each test case contains an integer $ n $ ( $ 1 \le n \le 5000 $ ) — the length of the string $ s $ .
The second line of each test case contains a string $ s $ of length $ n $ , consisting of the characters '1' and '0'.
It is guaranteed that the sum of the values $ n^2 $ over all test cases in the test does not exceed $ 25 \cdot 10^6 $ .
输出格式
For each test case, output the maximum integer $ k $ ( $ 1 \le k \le n $ ) for which it is possible to obtain a string $ s $ consisting only of the characters '1' using the described operations.
输入输出样例
输入#1
5 5 00100 5 01000 7 1011101 3 000 2 10
输出#1
3 2 4 3 1
输入解题思路,AI测评打分。不知道怎么写?