CF1272C.Yet Another Broken Keyboard

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently, Norge found a string s=s1s2…sns = s_1 s_2 \ldots s_n consisting of nn lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string ss. Yes, all n(n+1)2\frac{n (n + 1)}{2} of them!

A substring of ss is a non-empty string x=s[a…b]=sasa+1…sbx = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b} (1≤a≤b≤n1 \leq a \leq b \leq 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 kk Latin letters c1,c2,…,ckc_1, c_2, \ldots, c_k out of 2626.

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

最近,Norge 发现了一个由 nn 个小写拉丁字母组成的字符串 s=s1s2…sns = s_1 s_2 \ldots s_n。为了提升打字速度,他决定输入字符串 ss 的所有子串——没错,总共 n(n+1)2\frac{n (n + 1)}{2} 个!

字符串 ss 的一个子串是非空字符串 x=s[a…b]=sasa+1…sbx = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}(其中 1≤a≤b≤n1 \leq a \leq b \leq n)。例如,“auto” 和 “ton” 都是 “automaton” 的子串。

刚开始练习不久,Norge 就发现他的键盘坏了:他只能使用全部 26 个拉丁字母中的 kk 个字母 c1,c2,…,ckc_1, c_2, \ldots, c_k。

此后,Norge 想知道:利用这个坏掉的键盘,他还能输入字符串 ss 的多少个子串?请帮助他求出这个数目。

输入格式

The first line contains two space-separated integers nn and kk (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5, 1≤k≤261 \leq k \leq 26) — the length of the string ss and the number of Latin letters still available on the keyboard.

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

The third line contains kk space-separated distinct lowercase Latin letters c1,c2,…,ckc_1, c_2, \ldots, c_k — the letters still available on the keyboard.

第一行包含两个以空格分隔的整数 nn 和 kk(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,1≤k≤261 \leq k \leq 26)—— 分别表示字符串 ss 的长度以及键盘上仍可用的拉丁字母个数。

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

第三行包含 kk 个以空格分隔的互不相同的小写拉丁字母 c1,c2,…,ckc_1, c_2, \ldots, c_k —— 表示键盘上仍可用的字母。

输出格式

Print a single number — the number of substrings of ss that can be typed using only available letters c1,c2,…,ckc_1, c_2, \ldots, c_k.

输出一个整数——字符串 ss 中仅由可用字母 c1,c2,…,ckc_1, c_2, \ldots, c_k 构成的子串个数。

输入输出样例

  • 输入#1

    7 2
    abacaba
    a b

    输出#1

    12
  • 输入#2

    10 3
    sadfaasdda
    f a d

    输出#2

    21
  • 输入#3

    7 1
    aaaaaaa
    b

    输出#3

    0

说明/提示

In the first example Norge can print substrings s[1…2]s[1\ldots2], s[2…3]s[2\ldots3], s[1…3]s[1\ldots3], s[1…1]s[1\ldots1], s[2…2]s[2\ldots2], s[3…3]s[3\ldots3], s[5…6]s[5\ldots6], s[6…7]s[6\ldots7], s[5…7]s[5\ldots7], s[5…5]s[5\ldots5], s[6…6]s[6\ldots6], s[7…7]s[7\ldots7].

在第一个例子中,Norge 可以打印子串 s[1…2]s[1\ldots2]、s[2…3]s[2\ldots3]、s[1…3]s[1\ldots3]、s[1…1]s[1\ldots1]、s[2…2]s[2\ldots2]、s[3…3]s[3\ldots3]、s[5…6]s[5\ldots6]、s[6…7]s[6\ldots7]、s[5…7]s[5\ldots7]、s[5…5]s[5\ldots5]、s[6…6]s[6\ldots6]、s[7…7]s[7\ldots7]。

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

首页