A12714 | Letters Shop
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The letters shop showcase is a string $s$ , consisting of $n$ 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 $s$ .
There are $m$ friends, the $i$ -th of them is named $t_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 $s$ ="arrayhead" and $t_i$ ="arya" $5$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="harry" $6$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="ray" $5$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="r" $2$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="areahydra" all $9$ letters have to be bought ("arrayhead").
It is guaranteed that every friend can construct her/his name using the letters from the string $s$ .
Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $s$ .
There are $m$ friends, the $i$ -th of them is named $t_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 $s$ ="arrayhead" and $t_i$ ="arya" $5$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="harry" $6$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="ray" $5$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="r" $2$ letters have to be bought ("arrayhead").
- For example, for $s$ ="arrayhead" and $t_i$ ="areahydra" all $9$ letters have to be bought ("arrayhead").
It is guaranteed that every friend can construct her/his name using the letters from the string $s$ .
Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
输入格式
The first line contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the length of showcase string $s$ .
The second line contains string $s$ , consisting of exactly $n$ lowercase Latin letters.
The third line contains one integer $m$ ( $1 \le m \le 5 \cdot 10^4$ ) — the number of friends.
The $i$ -th of the next $m$ lines contains $t_i$ ( $1 \le |t_i| \le 2 \cdot 10^5$ ) — the name of the $i$ -th friend.
It is guaranteed that $\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$ .
The second line contains string $s$ , consisting of exactly $n$ lowercase Latin letters.
The third line contains one integer $m$ ( $1 \le m \le 5 \cdot 10^4$ ) — the number of friends.
The $i$ -th of the next $m$ lines contains $t_i$ ( $1 \le |t_i| \le 2 \cdot 10^5$ ) — the name of the $i$ -th friend.
It is guaranteed that $\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 $s$ 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 $s$ .
It is guaranteed that every friend can construct her/his name using the letters from the string $s$ .
输入输出样例
输入 #1
9 arrayhead 5 arya harry ray r areahydra
输出 #1
5 6 5 2 9
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted