CF1917B.Erase First or Second Letter

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string ss of length nn. 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.

给你一个长度为 nn 的字符串 ss。我们定义可在该字符串上执行的两种操作:

  • 删除字符串的第一个字符;
  • 删除字符串的第二个字符。

你的任务是求出:对初始字符串任意次(可能为零次)、以任意顺序执行上述操作,所能生成的互不相同的非空字符串的个数。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains nn (1≤n≤1051 \leq n \leq 10^5) — the length of the string.

The second line of each test case contains the string ss. It is guaranteed that the string only contains lowercase letters of the English alphabet.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示字符串的长度。

每个测试用例的第二行包含字符串 ss。保证该字符串仅由小写英文字母组成。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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: aa, aaaa, aaaaaa, aaaaaaaa, aaaaaaaaaa.

In the third test case, for example, the word baba can be reached in the following way:

  • remove the first character of the current string ababaababa, getting babababa;
  • remove the second character of the current string babababa, getting bbabba;
  • remove the second character of the current string bbabba, getting baba.

在第一个测试用例中,我们可以得到以下字符串:aa、aaaa、aaaaaa、aaaaaaaa、aaaaaaaaaa。

在第三个测试用例中,例如,单词 baba 可以通过以下方式得到:

  • 移除当前字符串 ababaababa 的第一个字符,得到 babababa;
  • 移除当前字符串 babababa 的第二个字符,得到 bbabba;
  • 移除当前字符串 bbabba 的第二个字符,得到 baba。

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

首页