CF1791D.Distinct Split
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's denote the f(x) function for a string x as the number of distinct characters that the string contains. For example f(abc)=3, f(bbbbb)=1, and f(babacaba)=3.
Given a string s, split it into two non-empty strings a and b such that f(a)+f(b) is the maximum possible. In other words, find the maximum possible value of f(a)+f(b) such that a+b=s (the concatenation of string a and string b is equal to string s).
我们用 f(x) 表示字符串 x 的不同字符个数。例如:f(abc)=3,f(bbbbb)=1,f(babacaba)=3。
给定一个字符串 s,将其分割为两个非空字符串 a 和 b,使得 f(a)+f(b) 尽可能大。换言之,求满足 a+b=s(即字符串 a 与字符串 b 的拼接等于字符串 s)时,f(a)+f(b) 的最大可能值。
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n (2≤n≤2⋅105) — the length of the string s.
The second line contains the string s, consisting of lowercase English letters.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105),表示字符串 s 的长度。
每个测试用例的第二行包含字符串 s,由小写英文字母组成。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single integer — the maximum possible value of f(a)+f(b) such that a+b=s.
对于每个测试用例,输出一个整数——满足 a+b=s 的 f(a)+f(b) 的最大可能值。
输入输出样例
输入#1
5 2 aa 7 abcabcd 5 aaaaa 10 paiumoment 4 aazz
输出#1
2 7 2 10 3
说明/提示
For the first test case, there is only one valid way to split aa into two non-empty strings a and a, and f(a)+f(a)=1+1=2.
For the second test case, by splitting abcabcd into abc and abcd we can get the answer of f(abc)+f(abcd)=3+4=7 which is maximum possible.
For the third test case, it doesn't matter how we split the string, the answer will always be 2.
对于第一个测试用例,将字符串 aa 拆分为两个非空字符串 a 和 a 只有一种合法方式,且 f(a)+f(a)=1+1=2。
对于第二个测试用例,将字符串 abcabcd 拆分为 abc 和 abcd,可得到 f(abc)+f(abcd)=3+4=7,这是可能的最大值。
对于第三个测试用例,无论以何种方式拆分该字符串,答案恒为 2。
输入解题思路,AI测评打分。不知道怎么写?