京セラプログラミングコンテスト2023(AtCoder Beginner Contest 305)
G
Banned Substrings
AtCoder
⌀ 1989
原题
← Ex→
翻译中…

Problem Statement

翻译中…

You are given a set $S=\lbrace s _ 1,s _ 2,\ldots,s _ M\rbrace$ of non-empty strings of length at most $6$ consisting of a and b. Find the number of strings $T$ of length $N$ consisting of a and b that satisfy the following condition:

翻译中…
  • $T$ does not contain $s _ i$ as a consecutive substring for any $s _ i\in S$.
翻译中…

Since the answer can be enormous, find it modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $1\leq N\leq10^{18}$
  • $1\leq M\leq126$
  • $N$ and $M$ are integers.
  • $s _ i$ is a non-empty string of length at most $6$ consisting of a and b.
  • $s _ i\neq s _ j\ (1\leq i\lt j\leq M)$
翻译中…

Input

翻译中…

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

翻译中…

N M
s _ 1
s _ 2
\vdots
s _ M

翻译中…

Output

翻译中…

Print the answer modulo $998244353$ in a single line.

翻译中…

样例

Input #1
4 3
aab
bbab
abab
Output #1
10
There are $10$ strings of length $4$ consisting of `a` and `b` that do not contain `aab`, `bbab`, or `abab` as consecutive substrings: `aaaa`, `abaa`, `abba`, `abbb`, `baaa`, `baba`, `babb`, `bbaa`, `bbba`, and `bbbb`. Thus, you should print $10$.
Input #2
20 1
aa
Output #2
17711
Input #3
1000000007 28
bbabba
bbbbaa
aabbab
bbbaba
baaabb
babaab
bbaaba
aabaaa
aaaaaa
aabbaa
bbaaaa
bbaabb
bbabab
aababa
baaaba
ababab
abbaba
aabaab
ababaa
abbbba
baabaa
aabbbb
abbbab
baaaab
baabbb
ababbb
baabba
abaaaa
Output #3
566756841
Print the answer modulo $998244353$.
题目信息
题号
abc305_g
时间限制
2 s
内存限制
1024 MB

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