CF1187B.Letters Shop

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The letters shop showcase is a string ss, consisting of nn lowercase Latin letters. As the name tells, letters are sold in the shop.

Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string ss.

There are mm friends, the ii-th of them is named tit_i. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount.

  • For example, for ss="arrayhead" and tit_i="arya" 55 letters have to be bought ("arrayhead").
  • For example, for ss="arrayhead" and tit_i="harry" 66 letters have to be bought ("arrayhead").
  • For example, for ss="arrayhead" and tit_i="ray" 55 letters have to be bought ("arrayhead").
  • For example, for ss="arrayhead" and tit_i="r" 22 letters have to be bought ("arrayhead").
  • For example, for ss="arrayhead" and tit_i="areahydra" all 99 letters have to be bought ("arrayhead").

It is guaranteed that every friend can construct her/his name using the letters from the string ss.

Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.

字母商店的展示字符串为 ss,由 nn 个小写拉丁字母组成。顾名思义,商店出售字母。

字母按从左到右的顺序逐个出售。任意顾客只能购买字符串 ss 的某个前缀。

共有 mm 位朋友,其中第 ii 位朋友的名字为 tit_i。每位朋友都计划估算如下数值:若想用所购字母拼出自己的名字,最少需要购买多少个字母(即最短前缀的长度)?当且仅当所购字母中每种字母的数量均不少于名字中对应字母所需数量时,该名字才可被拼出。

  • 例如,当 ss = "arrayhead" 且 tit_i = "arya" 时,需购买 55 个字母("arrayhead")。
  • 例如,当 ss = "arrayhead" 且 tit_i = "harry" 时,需购买 66 个字母("arrayhead")。
  • 例如,当 ss = "arrayhead" 且 tit_i = "ray" 时,需购买 55 个字母("arrayhead")。
  • 例如,当 ss = "arrayhead" 且 tit_i = "r" 时,需购买 22 个字母("arrayhead")。
  • 例如,当 ss = "arrayhead" 且 tit_i = "areahydra" 时,需购买全部 99 个字母("arrayhead")。

题目保证每位朋友均能使用字符串 ss 中的字母拼出自己的名字。

注意:各位朋友所估算的数值相互独立;他们仅进行估算,并不会实际购买字母。

输入格式

The first line contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the length of showcase string ss.

The second line contains string ss, consisting of exactly nn lowercase Latin letters.

The third line contains one integer mm (1≤m≤5⋅1041 \le m \le 5 \cdot 10^4) — the number of friends.

The ii-th of the next mm lines contains tit_i (1≤∣ti∣≤2⋅1051 \le |t_i| \le 2 \cdot 10^5) — the name of the ii-th friend.

It is guaranteed that ∑i=1m∣ti∣≤2⋅105\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 展示字符串 ss 的长度。

第二行包含字符串 ss,由恰好 nn 个小写拉丁字母组成。

第三行包含一个整数 mm(1≤m≤5⋅1041 \le m \le 5 \cdot 10^4)—— 朋友的数量。

接下来的 mm 行中,第 ii 行包含 tit_i(1≤∣ti∣≤2⋅1051 \le |t_i| \le 2 \cdot 10^5)—— 第 ii 个朋友的名字。

保证 ∑i=1m∣ti∣≤2⋅105\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5。

输出格式

For each friend print the length of the shortest prefix of letters from ss s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount.

It is guaranteed that every friend can construct her/his name using the letters from the string ss.

对于每位朋友,输出其姓名可被构造出来所需的字符串 ss 的最短前缀长度。当且仅当前缀中每种字母的出现次数均不少于该朋友姓名中对应字母的出现次数时,该姓名才可被构造出来。

题目保证:每位朋友均可利用字符串 ss 中的字母构造出自己的姓名。

输入输出样例

  • 输入#1

    9
    arrayhead
    5
    arya
    harry
    ray
    r
    areahydra

    输出#1

    5
    6
    5
    2
    9

输入解题思路,AI测评打分。不知道怎么写?

首页