309444: CF1679E. Typical Party in Dorm

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Typical Party in Dorm

题意翻译

给定一个长度为 $n(n\le 1000)$ ,仅由前 $17$ 个英文小写字母和问号组成的字符串 $s$。多次询问,每次给出一个由前 $17$ 个英文小写字母组成的字符集 $A$ ,你可以将 $s$ 中的问号任意替换成 $A$ 中的字母,求你能得到多少个不同的回文子串(两个子串不同,当且仅当起始位置,长度,两个子串的内容至少一个不同)。

题目描述

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 $ , $ \ldots $ , $ 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 $ 998\,244\,353 $ . 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 \le n \le 1\,000 $ ) — 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 $ , $ \ldots $ , $ p $ , $ q $ }. The third line contains a single integer $ q $ ( $ 1 \le q \le 2 \cdot 10^5 $ ) — 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 \le |t| \le 17 $ ). It is guaranteed that all letters in the string belong to the set { $ a $ , $ b $ , $ c $ , $ \ldots $ , $ 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 $ 998\,244\,353 $ .

输入输出样例

输入样例 #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: 1. a — substring \[ $ 1 $ ; $ 1 $ \]. 2. b — substring \[ $ 2 $ ; $ 2 $ \]. 3. a — substring \[ $ 3 $ ; $ 3 $ \]. 4. a — substring \[ $ 4 $ ; $ 4 $ \]. 5. a — substring \[ $ 5 $ ; $ 5 $ \]. 6. b — substring \[ $ 6 $ ; $ 6 $ \]. 7. a — substring \[ $ 7 $ ; $ 7 $ \]. 8. aa — substring \[ $ 3 $ ; $ 4 $ \]. 9. aa — substring \[ $ 4 $ ; $ 5 $ \]. 10. aba — substring \[ $ 1 $ ; $ 3 $ \]. 11. aaa — substring \[ $ 3 $ ; $ 5 $ \]. 12. aba — substring \[ $ 5 $ ; $ 7 $ \]. 13. baaab — substring \[ $ 2 $ ; $ 6 $ \]. 14. abaaaba — substring \[ $ 1 $ ; $ 7 $ \]. In the third request, we get 4 lines: abaaaba, abababa, abbaaba, abbbaba.

Input

题意翻译

给定一个长度为 $n(n\le 1000)$ ,仅由前 $17$ 个英文小写字母和问号组成的字符串 $s$。多次询问,每次给出一个由前 $17$ 个英文小写字母组成的字符集 $A$ ,你可以将 $s$ 中的问号任意替换成 $A$ 中的字母,求你能得到多少个不同的回文子串(两个子串不同,当且仅当起始位置,长度,两个子串的内容至少一个不同)。

Output

题目大意:
给定一个长度为 \( n (n \le 1000) \) 的字符串 \( s \),该字符串由前 17 个英文小写字母和问号组成。多次询问,每次给出一个由前 17 个英文小写字母组成的字符集 \( A \),你可以将 \( s \) 中的问号任意替换成 \( A \) 中的字母,求你能得到多少个不同的回文子串(两个子串不同,当且仅当起始位置,长度,两个子串的内容至少一个不同)。

输入输出数据格式:
输入格式:
- 第一行包含一个整数 \( n \)(\( 1 \le n \le 1000 \))——字符串 \( s \) 的长度。
- 第二行包含字符串 \( s \),由 \( n \) 个小写拉丁字母和问号组成。保证字符串中的所有字母都属于集合 \{ a, b, c, \ldots, p, q \}。
- 第三行包含一个整数 \( q \)(\( 1 \le q \le 2 \cdot 10^5 \))——询问的数量。
- 接下来 \( q \) 行,每行包含一个字符串 \( t \)——可以替换问号的字符集(\( 1 \le |t| \le 17 \))。保证字符串中的所有字母都属于集合 \{ a, b, c, \ldots, p, q \},且每个字母最多出现一次。

输出格式:
- 对于每个询问,打印一个数字——从字符串 \( s \) 获得的所有可能的字符串中的回文子串的总数,模 \( 998\,244\,353 \)。题目大意: 给定一个长度为 \( n (n \le 1000) \) 的字符串 \( s \),该字符串由前 17 个英文小写字母和问号组成。多次询问,每次给出一个由前 17 个英文小写字母组成的字符集 \( A \),你可以将 \( s \) 中的问号任意替换成 \( A \) 中的字母,求你能得到多少个不同的回文子串(两个子串不同,当且仅当起始位置,长度,两个子串的内容至少一个不同)。 输入输出数据格式: 输入格式: - 第一行包含一个整数 \( n \)(\( 1 \le n \le 1000 \))——字符串 \( s \) 的长度。 - 第二行包含字符串 \( s \),由 \( n \) 个小写拉丁字母和问号组成。保证字符串中的所有字母都属于集合 \{ a, b, c, \ldots, p, q \}。 - 第三行包含一个整数 \( q \)(\( 1 \le q \le 2 \cdot 10^5 \))——询问的数量。 - 接下来 \( q \) 行,每行包含一个字符串 \( t \)——可以替换问号的字符集(\( 1 \le |t| \le 17 \))。保证字符串中的所有字母都属于集合 \{ a, b, c, \ldots, p, q \},且每个字母最多出现一次。 输出格式: - 对于每个询问,打印一个数字——从字符串 \( s \) 获得的所有可能的字符串中的回文子串的总数,模 \( 998\,244\,353 \)。

加入题单

算法标签: