博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1272C --- Yet Another Broken Keyboard】
阅读量:2038 次
发布时间:2019-04-28

本文共 1992 字,大约阅读时间需要 6 分钟。

【CodeForces 1272C --- Yet Another Broken Keyboard】

题目来源:

Description

Recently, Norge found a string s=s1s2…sn consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all n(n+1)2 of them!

A substring of s is a non-empty string x=s[a…b]=sasa+1…sb (1≤a≤b≤n). For example, “auto” and “ton” are substrings of “automaton”.

Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c1,c2,…,ck out of 26.

After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.

Input

The first line contains two space-separated integers n and k (1≤n≤2⋅105, 1≤k≤26) — the length of the string s and the number of Latin letters still available on the keyboard.

The second line contains the string s consisting of exactly n lowercase Latin letters.

The third line contains k space-separated distinct lowercase Latin letters c1,c2,…,ck — the letters still available on the keyboard.

Output

Print a single number — the number of substrings of s that can be typed using only available letters c1,c2,…,ck.

Sample Input

7 2

abacaba
a b

Sample Output

12

AC代码:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'bool arr[26];using ll = long long;int main(){
SIS; char ch; int n,k; cin >> n >> k; string s; cin >> s; for(int i=0;i
> ch; arr[ch-'a']=true; } ll ans=0,cnt=0; for(int i=0;i
#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'using ll = long long;int main(){
SIS; int n,k,cnt=0; cin >> n >> k; string s; char ch; cin >> s; map
m; for(int i=0;i
> ch; m[ch-'a']=true; } vector
v; for(int i=0;i

转载地址:http://lsyof.baihongyu.com/

你可能感兴趣的文章
Linux修改文件及文件夹权限
查看>>
在PPT和Word中添加带有语法高亮的代码块
查看>>
iOS5:[UIDevice uniqueIdentifier]的替代方案
查看>>
四步轻松实现用Visio画UML类图
查看>>
CocoaTouch框架一览表
查看>>
Android anotations试用
查看>>
【Android框架进阶〖00〗】ThinkAndroid注解机制
查看>>
Associated Objects
查看>>
一个完整的Android ListView+网络接口读取+JSON处理的Demo
查看>>
ios 蓝牙
查看>>
iOS 类似Android.9图片拉伸
查看>>
ReactiveCocoa
查看>>
展现学习能力,可能比展现能力更重要
查看>>
一些资料
查看>>
class dump
查看>>
使用Objective-C的文档生成工具:appledoc
查看>>
Appledoc 安装
查看>>
class-dump获取部分iOS app头文件信息
查看>>
RSSI与LQI、接收距离d之间的关系(转)
查看>>
Method Swizzling
查看>>