Grammarly
Time limit2sMemory limit512 MB
Given a string up to 300,000 characters, count simple paths from the whole string through distinct substrings where each step deletes one character, modulo 998244353.
- Level
Hard9 of 10
- Topics
- String, Dynamic programming, Trie
- Solved
- No attempts yet
Problem
CauchySheep has a string s. He looked at all its different non-empty substrings and added a directed edge from a to b if and b is a substring of a. Count the simple paths that start from s in this graph, modulo 998 244 353.
Input
The first line contains a string s of lowercase Latin letters ().
Output
Print one integer: the number of simple paths starting from s, modulo 998 244 353.
Hint
