Typical Party in Dorm Codeforces Solution | Codeforces Problem Solution 2022
Today is a holiday in the residence hall — Oleh arrived, in honor of which the girls gave him a string. Oleh liked the gift a lot, so he immediately thought up and offered you, his best friend, the following problem.
You are given a string of length , which consists of the first lowercase Latin letters {, , , , , } and question marks. And queries. Each query is defined by a set of pairwise distinct lowercase first letters of the Latin alphabet, which can be used to replace the question marks in the string .
The answer to the query is the sum of the number of distinct substrings that are palindromes over all strings that can be obtained from the original string by replacing question marks with available characters. The answer must be calculated modulo .
Pay attention! Two substrings are different when their start and end positions in the string are different. So, the number of different substrings that are palindromes for the string aba will be : a, b, a, aba.
Consider examples of replacing question marks with letters. For example, from the string aba??ee when querying {, } you can get the strings ababaee or abaaaee but you cannot get the strings pizza, abaee, abacaba, aba?fee, aba47ee, or abatree.
Recall that a palindrome is a string that reads the same from left to right as from right to left.
The first line contains a single integer () — the length of the string .
The second line contains the string , which consists of lowercase Latin letters and question marks. It is guaranteed that all letters in the string belong to the set {, , , , , }.
The third line contains a single integer () — the number of queries.
This is followed by lines, each containing a single line — a set of characters that can replace question marks (). It is guaranteed that all letters in the string belong to the set {, , , , , } and occur at most once.
For each query print one number — the total numbers of palindromic substrings in all strings that can be obtained from the string , modulo .
Join Now for Solution:-
No comments:
Post a Comment