#P14185. 回文子串划分计数

回文子串划分计数

Problem Description

Given a string SS that contains only lowercase letters.
Find the number of ways to partition SS into several non-overlapping palindromic substrings, modulo 998244353998244353.


Below is the formal statement.

Please compute the number of ways (with no limit on the count) to choose some intervals [L1,R1],[L2,R2],,[Lm,Rm][L_1,R_1],[L_2,R_2],\cdots,[L_m,R_m] such that the following conditions are satisfied, modulo 998244353998244353:

  • L1=1L_1=1, Rm=SR_m=|S|.
  • For all i[1,m]i\in[1,m], LiRiL_i\le R_i.
  • For all i[1,m)i\in[1,m), Ri+1=Li+1R_i+1=L_{i+1}.
  • For all i[1,m]i\in[1,m], the string SLiSLi+1SRiS_{L_i}S_{L_i+1}\cdots S_{R_i} is a palindrome (indices start from 11).

Input Format

One line: the string SS.

Output Format

One line: the number of valid ways modulo 998244353998244353.

abbba
5
aabcccbaa
22
abcbabcacabbcbabbcabbbcbabcbabcbcaacaaa
217952

Hint

  • For 100%100\% of the testdata, 1S1061\le |S|\le10^6, and SS contains only lowercase letters.

Translated by ChatGPT 5