Letters Shop
2 seconds
256 megabytes
standard input
standard output
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 titi. 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 titi="arya" 55 letters have to be bought ("arrayhead").
- For example, for ss="arrayhead" and titi="harry" 66 letters have to be bought ("arrayhead").
- For example, for ss="arrayhead" and titi="ray" 55 letters have to be bought ("arrayhead").
- For example, for ss="arrayhead" and titi="r" 22 letters have to be bought ("arrayhead").
- For example, for ss="arrayhead" and titi="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.
The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — 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≤m≤5⋅104) — the number of friends.
The ii-th of the next mm lines contains titi (1≤|ti|≤2⋅1051≤|ti|≤2⋅105) — the name of the ii-th friend.
It is guaranteed that ∑i=1m|ti|≤2⋅105∑i=1m|ti|≤2⋅105.
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.
9
arrayhead
5
arya
harry
ray
r
areahydra
5
6
5
2
9
http://codeforces.com/problemset/problem/1187/B
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll; vector<ll> p[];
ll a[];
int main(){
ll n;
cin>>n;
string s;
cin>>s;
for(int i=;i<n;i++){
p[s[i]-'a'].push_back(i);//存储每个字母对应的下标,按顺序
}
ll m;
cin>>m;
while(m--){
memset(a,,sizeof(a));//存储子串中字母出现的次数
string z;
cin>>z;
ll len=z.size(),ans=;
for(int i=;i<len;i++){
ans=max(ans,p[z[i]-'a'][a[z[i]-'a']]+);
a[z[i]-'a']++;
}
cout<<ans<<endl;
}
return ;
}
Letters Shop的更多相关文章
- Educational Codeforces Round 67
Educational Codeforces Round 67 CF1187B Letters Shop 二分 https://codeforces.com/contest/1187/submissi ...
- Codeforces Educational Codeforces Round 67
目录 Contest Info Solutions A. Stickers and Toys B. Letters Shop C. Vasya And Array D. Subarray Sortin ...
- Codeforces Edu Round 67 A-C + E
A. Stickers and Toys 考虑尽量先买\(max(s, t)\)个里面单独的.那么如果\(s + t > n\)那么\(s + t - n\)的部分就该把\(min(s, t)\ ...
- [LeetCode] Remove Duplicate Letters 移除重复字母
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- codeforces 632+ E. Thief in a Shop
E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- 316. Remove Duplicate Letters
Given a string which contains only lowercase letters, remove duplicate letters so that every letter ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- Magicodes.Shop——版本历史
Magicodes.Shop为湖南心莱信息科技有限公司(xin-lai.com)Magicodes系列产品之一. 产品中引用的Magicodes系列Nuget包的开源库地址为:https://gith ...
随机推荐
- 新手如何学python?
在学习Python前,你应该规划好自己的学习方向,毕竟Python的方向比较多,比如: web开发 爬虫 自动化开发(运维,测试).脚本开发 大数据(数据挖掘,数据分析) 人工智能.机器学习 选择好自 ...
- 1. VMware搭建Linux环境,安装配置centos6.5
1. 安装VMware,后新建虚拟机 2. 为我们的虚拟机挂载操作系统 3.开启我们的虚拟机,为我们的虚拟机进行安装操作系统 4.配置虚拟机连接网络 修改linux的mac地址 修改mac地址配置文件 ...
- Tensorflow教程(1)Tensorflow的下载和安装
人工智能已经成为了目前的大趋势,作为程序员的我们也应该跟着时代进步.Tensorflow作为人工智能领域的重要工具,被广泛的使用在机器学习的应用当中. Tensorflow使用人数众多.社区完善,所以 ...
- Hash的应用2
代码: #include <stdio.h> #define OFFSET 500000//偏移量 ];//记录每个数是否出现,出现为1,不出现为0 int main(){ int n,m ...
- Shell文件
#!/bin/bashecho "======================欢迎来到进爷故事会======================="echo "******* ...
- Kubernetes1.15 部署 coredns
coredns.yaml文件如下所示 # __MACHINE_GENERATED_WARNING__ apiVersion: v1 kind: ServiceAccount metadata: nam ...
- python爬虫笔记之re.match匹配,与search、findall区别
为什么re.match匹配不到?re.match匹配规则怎样?(捕一下seo) re.match(pattern, string[, flags]) pattern为匹配规则,即输入正则表达式. st ...
- 关于ftp响应码的分析【转载】
转载地址: http://www.jb51.net/article/26649.htm 1开头-成功 2开头-成功 3开头-权限问题 4开头-文件问题 5开头-服务器问题 150 FILE: %s 1 ...
- Java项目案例之---登录和修改(JSP)
登录和修改(JSP) 通过案例学习jsp的常用知识点: 1.创建一个Map集合,用于存放学生信息,将学生信息存入Map中 2.通过page将需要的包导入 3.用request.getParameter ...
- 《VR入门系列教程》之13---相机与立体渲染
相机.透视图.视口.投影 渲染好的场景都需要一个可以供用户查看的视图,我们通常在3D场景中用相机来提供这种需求.相机相对场景有位置和方向,就像我们生活中的相机一样,它也提供透视图查看方式,这种 ...