#E. Nearly Shortest Repeating Substring

    远端评测题 2000ms 256MiB

Nearly Shortest Repeating Substring

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

给你一个长度为 nn 的字符串 ss ,它由小写字母组成。求最短字符串 kk 的长度,使得多个(可能是一个) kk 可以连接在一起,形成一个长度与 ss 相同的字符串,且最多只有一个不同的字符。

更正式地说,求最短字符串 kk 的长度,使得 $c = \underbrace{k + \cdots + k}_{x\rm\ \text{times}}$ 为某个正整数 xx ,字符串 sscc 的长度相同,且 cisic_i \neq s_i 中最多有一个 ii (即存在 0011 这样的位置)。

输入格式

The first line contains a single integer t t ( 1t103 1 \leq t \leq 10^3 ) — the number of test cases.

The first line of each test case contains a single integer n n ( 1n2105 1 \leq n \leq 2\cdot10^5 ) — the length of string s s .

The second line of each test case contains the string s s , consisting of lowercase Latin characters.

The sum of n n over all test cases does not exceed 2105 2\cdot10^5 .

样例 #1

样例输入 #1

5
4
abaa
4
abba
13
slavicgslavic
8
hshahaha
20
stormflamestornflame

样例输出 #1

1
4
13
2
10

The second

未参加
状态
已结束
规则
ACM/ICPC
题目
5
开始于
2024-8-5 8:45
结束于
2024-8-5 11:15
持续时间
2.5 小时
主持人
参赛人数
23