题库练习 Ternary String
← 上一题 下一题 →

A13370 | Ternary String

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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
C++ 编辑器
输入
输出