Measuring WAC-ness
Time limit1sMemory limit512 MB
Count subsequences equal to WAC in a base string repeated K times, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, String, Dynamic programming
- Solved
- No attempts yet
Problem
Consider a string of length . Let string be that string repeated times. You are interested in how wack the string is, so your task is to find the WAC-ness of this string.
The WAC-ness of a string is the number of times "WAC" appears as a subsequence of that string.
A subsequence of a string is a string that can be derived from the given string by deleting zero or more characters without changing the order of the remaining characters. Two subsequences are different if at least one of the remaining indices is different. For example, in the string "AABC", the subsequence formed by indices , , and is distinct from the subsequence formed by indices , , and .
As the answer can be very large, output the answer modulo .
Input
The first line contains two integers, and (, ), the length of the original string and the number of times that string is repeated to form . The second and final line contains the original string of characters, consisting of uppercase letters of the English alphabet.
Output
Output the WAC-ness of the string modulo .