CF1679E.Typical Party in Dorm
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 { a , b , c , … , p , q } 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 .
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 4 : a, b, a, aba.
Consider examples of replacing question marks with letters. For example, from the string aba??ee when querying { a , b } 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 n ( 1≤n≤1000 ) — 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 { a , b , c , … , p , q }.
The third line contains a single integer q ( 1≤q≤2⋅105 ) — 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 { a , b , c , … , p , q } 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 s , modulo 998244353 .
输入输出样例
输入#1
7 ab??aba 8 a b ab abc abcd abcde abcdef abcdefg
输出#1
14 13 55 105 171 253 351 465
输入#2
11 ??????????? 6 abcdefghijklmnopq ecpnkhbmlidgfjao olehfan codef glhf q
输出#2
900057460 712815817 839861037 756843750 70840320 66
说明/提示
Consider the first example and the first query in it. We can get only one string as a result of replacing the question marks — abaaaba. It has the following palindrome substrings:
- a — substring [ 1 ; 1 ].
- b — substring [ 2 ; 2 ].
- a — substring [ 3 ; 3 ].
- a — substring [ 4 ; 4 ].
- a — substring [ 5 ; 5 ].
- b — substring [ 6 ; 6 ].
- a — substring [ 7 ; 7 ].
- aa — substring [ 3 ; 4 ].
- aa — substring [ 4 ; 5 ].
- aba — substring [ 1 ; 3 ].
- aaa — substring [ 3 ; 5 ].
- aba — substring [ 5 ; 7 ].
- baaab — substring [ 2 ; 6 ].
- abaaaba — substring [ 1 ; 7 ].
In the third request, we get 4 lines: abaaaba, abababa, abbaaba, abbbaba.