#P10581. [蓝桥杯 2024 国 A] 重复的串

    ID: 12066 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2024矩阵加速KMP 算法蓝桥杯国赛

[蓝桥杯 2024 国 A] 重复的串

Problem Description

Given a string SS consisting only of lowercase letters, ask how many strings of length nn consisting only of lowercase letters contain SS exactly twice. Output the answer modulo 998 244 353998\ 244\ 353.

Input Format

Input one line containing a string SS and an integer nn, separated by a space.

Output Format

Output one line containing one integer representing the answer.

aba 6
53
aba 10
77907666

Hint

For 40%40\% of the test cases, n20n \le 20 and S6|S| \le 6.
For another 10%10\% of the test cases, n500n \le 500 and S2|S| \le 2.
For 70%70\% of the test cases, n105n \le 10^5.
For all test cases, 1n1091 \le n \le 10^9 and 1S301 \le |S| \le 30.

Translated by ChatGPT 5