CF1354B.Ternary String
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
给你一个字符串 s,其中每个字符均为 1、2 或 3。你需要选出 s 的最短连续子串,使得该子串中至少包含这三个字符各一次。
字符串 s 的一个连续子串是指:从 s 的开头删去若干(可能为零)个字符,并从 s 的末尾删去若干(可能为零)个字符后所得到的字符串。
输入格式
The first line contains one integer t (1≤t≤20000) — the number of test cases.
Each test case consists of one line containing the string s (1≤∣s∣≤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.
第一行包含一个整数 t(1≤t≤20000)—— 测试用例的数量。
每个测试用例由一行组成,该行包含字符串 s(1≤∣s∣≤200000)。保证字符串 s 中的每个字符均为 1、2 或 3。
所有测试用例中字符串长度的总和不超过 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.
对于每个测试用例,输出一个整数——即字符串 s 中包含全部三种字符(每种至少出现一次)的最短连续子串的长度。若不存在这样的子串,则输出 0。
输入输出样例
输入#1
7 123 12222133333332 112233 332211 12121212 333333 31121
输出#1
3 3 4 4 0 0 4
说明/提示
Consider the example test:
In the first test case, the substring 123 can be used.
In the second test case, the substring 213 can be used.
In the third test case, the substring 1223 can be used.
In the fourth test case, the substring 3221 can be used.
In the fifth test case, there is no character 3 in s.
In the sixth test case, there is no character 1 in s.
In the seventh test case, the substring 3112 can be used.
考虑以下示例测试:
在第一个测试用例中,可以使用子串 123。
在第二个测试用例中,可以使用子串 213。
在第三个测试用例中,可以使用子串 1223。
在第四个测试用例中,可以使用子串 3221。
在第五个测试用例中,字符串 s 中不存在字符 3。
在第六个测试用例中,字符串 s 中不存在字符 1。
在第七个测试用例中,可以使用子串 3112。
输入解题思路,AI测评打分。不知道怎么写?