第六回日本最強プログラマー学生選手権-予選-(AtCoder Regular Contest 201)
C
Prefix Covering
AtCoder
⌀ 1789
原题
← BD →
翻译中…

Problem Statement

翻译中…

A non-empty string where every character is A or B is called an AB string.

翻译中…

A set $X$ consisting of AB strings is called a good set when it satisfies the following:

翻译中…
  • Every AB string of length $10^{100}$ has some element of $X$ as a prefix.
翻译中…

You are given distinct AB strings $S_1, S_2, \ldots, S_N$. For each $k=1,2,\ldots,N$, find the number, modulo $998244353$, of subsets of the set $\lbrace S_1,S_2,\ldots,S_k\rbrace$ that are good sets.

翻译中…

Constraints

翻译中…
  • $1\leq N\leq 2\times 10^5$
  • $S_1, S_2, \ldots, S_N$ are distinct AB strings.
  • $\sum_{1\leq i\leq N}|S_i|\leq 5\times 10^5$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
S_1
S_2
\vdots
S_N

翻译中…

Output

翻译中…

Output $N$ lines. The $k$-th line should contain the number, modulo $998244353$, of subsets of the set $\lbrace S_1,S_2,\ldots,S_k\rbrace$ that are good sets.

翻译中…

样例

Input #1
6
A
B
BA
BB
AA
AB
Output #1
0
1
2
5
10
25
- For $k=1$: There are no good subsets. - For $k=2$: There is $1$ good subset: $\lbrace S_1,S_2\rbrace$. - For $k=3$: There are $2$ good subsets: $\lbrace S_1,S_2\rbrace$, $\lbrace S_1,S_2,S_3\rbrace$. - For $k=4$: There are $5$ good subsets: $\lbrace S_1,S_2\rbrace$, $\lbrace S_1,S_2,S_3\rbrace$, $\lbrace S_1,S_2,S_4\rbrace$, $\lbrace S_1,S_3,S_4\rbrace$, $\lbrace S_1,S_2,S_3,S_4\rbrace$.
Input #2
10
A
B
AABA
AABB
AB
AA
AAA
BB
AAB
BA
Output #2
0
1
2
4
8
20
41
82
170
425
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。