307413: CF1354B. Ternary String
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Ternary String
题意翻译
有一个长度为$n$的字符集为$\{1,2,3\}$的字符串$S$。现在需要求出最短的连续子串,使得这个子串中存在$\{1,2,3\}$三种数字。题目描述
You are given a string $ s $ such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of $ s $ such that it contains each of these three characters at least once. A contiguous substring of string $ s $ is a string that can be obtained from $ s $ by removing some (possibly zero) characters from the beginning of $ s $ and some (possibly zero) characters from the end of $ s $ .输入输出格式
输入格式
The first line contains one integer $ t $ ( $ 1 \le t \le 20000 $ ) — the number of test cases. Each test case consists of one line containing the string $ s $ ( $ 1 \le |s| \le 200000 $ ). It is guaranteed that each character of $ s $ is either 1, 2, or 3. The sum of lengths of all strings in all test cases does not exceed $ 200000 $ .
输出格式
For each test case, print one integer — the length of the shortest contiguous substring of $ s $ containing all three types of characters at least once. If there is no such substring, print $ 0 $ instead.
输入输出样例
输入样例 #1
7
123
12222133333332
112233
332211
12121212
333333
31121
输出样例 #1
3
3
4
4
0
0
4