CF1633B.Minority
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s, consisting only of characters '0' and '1'.
You have to choose a contiguous substring of s and remove all occurrences of the character, which is a strict minority in it, from the substring.
That is, if the amount of '0's in the substring is strictly smaller than the amount of '1's, remove all occurrences of '0' from the substring. If the amount of '1's is strictly smaller than the amount of '0's, remove all occurrences of '1'. If the amounts are the same, do nothing.
You have to apply the operation exactly once. What is the maximum amount of characters that can be removed?
给你一个仅由字符 '0' 和 '1' 组成的字符串 s。
你需要选择 s 的一个连续子串,并从该子串中删除其中严格占少数的字符的所有出现。
也就是说,如果该子串中 '0' 的数量严格小于 '1' 的数量,则删除该子串中所有的 '0';如果 '1' 的数量严格小于 '0' 的数量,则删除该子串中所有的 '1';如果两者的数量相等,则不进行任何操作。
你必须恰好执行一次该操作。最多可以删除多少个字符?
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
The only line of each testcase contains a non-empty string s, consisting only of characters '0' and '1'. The length of s doesn't exceed 2⋅105.
The total length of strings s over all testcases doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例仅有一行,包含一个非空字符串 s,该字符串仅由字符 '0' 和 '1' 组成。字符串 s 的长度不超过 2⋅105。
所有测试用例中字符串 s 的总长度不超过 2⋅105。
输出格式
For each testcase, print a single integer — the maximum amount of characters that can be removed after applying the operation exactly once.
对于每个测试用例,输出一个整数——即恰好执行一次该操作后,最多可以删除的字符数量。
输入输出样例
输入#1
4 01 1010101010111 00110001000 1
输出#1
0 5 3 0
说明/提示
In the first testcase, you can choose substrings "0", "1" or "01". In "0" the amount of '0' is 1, the amount of '1' is 0. '1' is a strict minority, thus all occurrences of it are removed from the substring. However, since there were 0 of them, nothing changes. Same for "1". And in "01" neither of '0' or '1' is a strict minority. Thus, nothing changes. So there is no way to remove any characters.
In the second testcase, you can choose substring "10101010101". It contains 5 characters '0' and 6 characters '1'. '0' is a strict minority. Thus, you can remove all its occurrences. There exist other substrings that produce the same answer.
In the third testcase, you can choose substring "011000100". It contains 6 characters '0' and 3 characters '1'. '1' is a strict minority. Thus, you can remove all its occurrences.
在第一个测试用例中,你可以选择子串 "0"、"1" 或 "01"。在 "0" 中,字符 '0' 的数量为 1,字符 '1' 的数量为 0。'1' 是严格少数,因此该子串中所有 '1' 都将被移除。但由于 '1' 的数量为 0,故字符串不发生变化。对 "1" 同理。而在 "01" 中,'0' 和 '1' 均非严格少数,因此也不发生变化。所以无法移除任何字符。
在第二个测试用例中,你可以选择子串 "10101010101"。它包含 5 个字符 '0' 和 6 个字符 '1'。'0' 是严格少数,因此可以移除其所有出现。还存在其他能得出相同答案的子串。
在第三个测试用例中,你可以选择子串 "011000100"。它包含 6 个字符 '0' 和 3 个字符 '1'。'1' 是严格少数,因此可以移除其所有出现。
输入解题思路,AI测评打分。不知道怎么写?