CF1917B.Erase First or Second Letter
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s of length n. Let's define two operations you can apply on the string:
- remove the first character of the string;
- remove the second character of the string.
Your task is to find the number of distinct non-empty strings that can be generated by applying the given operations on the initial string any number of times (possibly zero), in any order.
给你一个长度为 n 的字符串 s。我们定义可在该字符串上执行的两种操作:
- 删除字符串的第一个字符;
- 删除字符串的第二个字符。
你的任务是求出:对初始字符串任意次(可能为零次)、以任意顺序执行上述操作,所能生成的互不相同的非空字符串的个数。
输入格式
Each test consists of multiple test cases. The first line contains a single 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 n (1≤n≤105) — the length of the string.
The second line of each test case contains the string s. It is guaranteed that the string only contains lowercase letters of the English alphabet.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示字符串的长度。
每个测试用例的第二行包含字符串 s。保证该字符串仅由小写英文字母组成。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single integer: the number of distinct non-empty strings you can get.
对于每个测试用例,输出一个整数:你能得到的不同非空字符串的个数。
输入输出样例
输入#1
5 5 aaaaa 1 z 5 ababa 14 bcdaaaabcdaaaa 20 abcdefghijklmnopqrst
输出#1
5 1 9 50 210
说明/提示
In the first test case, we can get the following strings: a, aa, aaa, aaaa, aaaaa.
In the third test case, for example, the word ba can be reached in the following way:
- remove the first character of the current string ababa, getting baba;
- remove the second character of the current string baba, getting bba;
- remove the second character of the current string bba, getting ba.
在第一个测试用例中,我们可以得到以下字符串:a、aa、aaa、aaaa、aaaaa。
在第三个测试用例中,例如,单词 ba 可以通过以下方式得到:
- 移除当前字符串 ababa 的第一个字符,得到 baba;
- 移除当前字符串 baba 的第二个字符,得到 bba;
- 移除当前字符串 bba 的第二个字符,得到 ba。
输入解题思路,AI测评打分。不知道怎么写?