GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Saturday 14 May 2022

Typical Party in Dorm Codeforces Solution | Codeforces Problem Solution 2022

E. Typical Party in Dorm
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 s of length n, which consists of the first 17 lowercase Latin letters {abcpq} and question marks. And q queries. Each query is defined by a set of pairwise distinct lowercase first 17 letters of the Latin alphabet, which can be used to replace the question marks in the string s.

Solution Click Below:-  CLICK HERE

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 s by replacing question marks with available characters. The answer must be calculated modulo 998244353.


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 4abaaba.

Consider examples of replacing question marks with letters. For example, from the string aba??ee when querying {ab} you can get the strings ababaee or abaaaee but you cannot get the strings pizzaabaeeabacabaaba?feeaba47ee, or abatree.

Recall that a palindrome is a string that reads the same from left to right as from right to left.

Input

The first line contains a single integer n (1n1000) — the length of the string s.

The second line contains the string s, which consists of n lowercase Latin letters and question marks. It is guaranteed that all letters in the string belong to the set {abcpq}.

The third line contains a single integer q (1q2105) — the number of queries.

This is followed by q lines, each containing a single line t — a set of characters that can replace question marks (1|t|17). It is guaranteed that all letters in the string belong to the set {abcpq} and occur at most once.

Output

For each query print one number — the total numbers of palindromic substrings in all strings that can be obtained from the string s, modulo 998244353.


Join Now for Solution:- 

No comments:

Post a Comment