CF1551B1.Wonderful Coloring - 1

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.

Paul and Mary have a favorite string ss which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:

  1. each letter of the string is either painted in exactly one color (red or green) or isn't painted;
  2. each two letters which are painted in the same color are different;
  3. the number of letters painted in red is equal to the number of letters painted in green;
  4. the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions.

E. g. consider a string ss equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure.

The example of a wonderful coloring of the string "kzaaa".

Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find kk — the number of red (or green, these numbers are equal) letters in a wonderful coloring.

这是问题 B2 的简化版本。在开始求解 B1 之前,你可能需要先阅读问题 B2。

保罗和玛丽有一个他们最喜欢的字符串 ss,该字符串由拉丁字母表中的小写字母组成。他们希望使用两种颜色(红色和绿色)的粉笔来为该字符串涂色。我们称一个字符串的涂色方案为“美妙的”,当且仅当满足以下条件:

  1. 字符串中的每个字母恰好被涂成一种颜色(红色或绿色),或者不涂色;
  2. 所有被涂成同一种颜色的字母互不相同;
  3. 被涂成红色的字母个数等于被涂成绿色的字母个数;
  4. 在所有满足前三个条件的涂色方案中,该方案所涂色的字母总数最大。

例如,考虑字符串 s=“kzaaa”s = \text{“kzaaa”}。图中展示了一种该字符串的美妙涂色方案。

字符串 “kzaaa” 的一种美妙涂色方案示例。

保罗和玛丽希望独立学会如何为该字符串找出一种美妙涂色方案。但由于他们年纪尚小,需要一点提示。请帮助他们找出 kk —— 即在一种美妙涂色方案中,被涂成红色(或绿色,这两个数目相等)的字母个数。

输入格式

The first line contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases. Then tt test cases follow.

Each test case consists of one non-empty string ss which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed 5050.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例由一个非空字符串 ss 组成,该字符串仅包含小写拉丁字母。字符串的字符数不超过 5050。

输出格式

For each test case, output a separate line containing one non-negative integer kk — the number of letters which will be painted in red in a wonderful coloring.

对于每个测试用例,输出一行,包含一个非负整数 kk —— 即在完美染色中被涂成红色的字母个数。

输入输出样例

  • 输入#1

    5
    kzaaa
    codeforces
    archive
    y
    xxxxxx

    输出#1

    2
    5
    3
    0
    1

说明/提示

The first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing 33 or more red letters because the total number of painted symbols will exceed the string's length.

The string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters "c", "o", "e" in red and the second ones in green. Let's paint the letters "d", "f" in red and "r", "s" in green. So every letter will be painted in red or green, hence the answer better than 55 doesn't exist.

The third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.

The fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.

The fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.

第一个测试用例包含题目陈述中给出的字符串。图中展示了一种优美的染色方案。不存在包含 33 个或更多红色字母的优美染色,因为被染色符号的总数将超过字符串的长度。

第二个测试用例中的字符串可按如下方式染色:将字母 “c”、“o”、“e” 的首次出现染为红色,第二次出现染为绿色;将字母 “d”、“f” 染为红色,字母 “r”、“s” 染为绿色。这样每个字母均被染为红色或绿色,因此不存在优于 55 的答案。

第三个测试用例包含一个由互不相同字母组成的字符串,因此你可以任选一组字符染为红色,只要该组大小不超过字符串长度的一半且尽可能大即可。

第四个测试用例仅含一个字母,该字母无法染为红色,否则将没有字母可染为绿色。

第五个测试用例包含一个由相同字母组成的字符串,因此最多只能将一个字母染为红色。

输入解题思路,AI测评打分。不知道怎么写?

首页