8572: Regular expression

内存限制:256 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

链接:https://ac.nowcoder.com/acm/contest/33192/G
来源:牛客网
Grammy has recently been interested in regular expression while focusing on cases where the alphabet consists of characters from aaa to zzz. Today she asks NIO some questions. Each question gives string AAA, asking the minimum length of expressions matching string AAA according to the matching rules and the number of all shortest expressions.

To learn detailed rules about how regular expressions match strings,
you can refer to https://en.wikipedia.org/wiki/Regular_expression.

Here we only consider characters from 'a' to 'z', '.', '?', '*', '+', '|', '(', ')'. It is assumed that the asterisk, the question mark and the plus sign have the highest priority, then concatenation and then alternation. Parentheses can be used to change the priority. For example, a(b|c)\texttt{a(b|c)}a(b|c) can match “ab” and “ac”. If there is no ambiguity then parentheses may be omitted. For example, (ab)c\texttt{(ab)c}(ab)c can be written as abc\texttt{abc}abc, and a|(b(c*))\texttt{a|(b(c*))}a|(b(c*)) can be written as a|bc*\texttt{a|bc*}a|bc*

Here are some examples of matching:


  • (or): gray|grey\texttt{gray|grey}gray|grey can match “gray” or “grey”.

  • (question mark): colou?r\texttt{colou?r}colou?r matches both “color” and “colour”.

  • (asterisk): ab*c\texttt{ab*c}ab*c matches “ac”, “abc”, “abbc”, “abbbc”, and so on.

  • (plus sign): ab+c\texttt{ab+c}ab+c matches “abc”, “abbc”, “abbbc”, and so on, but not “ac”.

  • (wildcard): a.b\texttt{a.b}a.b matches any string that contains an “a”, and then any character and then “b”; and a.*b\texttt{a.*b}a.*b matches any string that contains an “a”, and then the character “b” at some later point. More precisely, “ab” can be matched by a.*b\texttt{a.*b}a.*b but not a.b\texttt{a.b}a.b.

  • (concatenation): Let expression R=(ab|c)R=\texttt{(ab|c)}R=(ab|c) matches {ab,c}\{ ab, c\}{ab,c} and expression S=(d|ef)S=\texttt{(d|ef)}S=(d|ef) matches {d,ef}\{d, ef\}{d,ef}. Then, (RS)=((ab|c)(d|ef))(RS)=\texttt{((ab|c)(d|ef))}(RS)=((ab|c)(d|ef)) matches {abd,abef,cd,cef}\{abd, abef, cd, cef\}{abd,abef,cd,cef}
If you are not sure about whether a regular expression is valid, then you can use https://regex101.com/ to check its validity. Note that the character set we use is slightly different from the website. 

输入格式


The input contains only a single case.
The first line contains a single integer QQQ (1≤Q≤1000001\leq Q\leq 100\,0001Q100000), denoting the number of questions. The iii-th line of the following QQQ lines contain one string AAA consisting of lowercase letters (1≤∣A∣≤2000001\leq |A|\leq 200\,0001A200000), denoting the string AAA of the iii-th question. It is guaranteed that ∑∣A∣≤1000000\sum |A|\leq 1\,000\,000A1000000.

输出格式


For each question, output a single line containing 2 integers - the minimum length and the number to the question. Note that the answer may be extremely large, so please print it modulo 998244353998\,244\,353998244353 instead.

输入样例 复制

2
a
ab

输出样例 复制

1 2
2 6

分类标签