CF535D.Tavas and Malekas

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead.

Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little process on s. Malekas has a favorite string p. He determined all positions _x_1 < _x_2 < ... < x__k where p matches s. More formally, for each x__i (1 ≤ i ≤ k) he condition s__x__i__s__x__i + 1... s__x__i + |p| - 1 = p is fullfilled.

Then Malekas wrote down one of subsequences of _x_1, _x_2, ... x__k (possibly, he didn't write anything) on a piece of paper. Here a sequence b is a subsequence of sequence a if and only if we can turn a into b by removing some of its elements (maybe no one of them or all).

After Tavas woke up, Malekas told him everything. He couldn't remember string s, but he knew that both p and s only contains lowercase English letters and also he had the subsequence he had written on that piece of paper.

Tavas wonders, what is the number of possible values of s? He asked SaDDas, but he wasn't smart enough to solve this. So, Tavas asked you to calculate this number for him.

Answer can be very large, so Tavas wants you to print the answer modulo 109 + 7.

塔瓦斯是一种奇怪的生物。通常人们睡觉时会发出“zzz”的声音,而塔瓦斯睡觉时则会从口中吐出一个长度为 nn 的字符串 ss。

今天,塔瓦斯在马莱卡斯家睡着了。在他熟睡期间,马莱卡斯对字符串 ss 进行了一次小操作。马莱卡斯有一个他最喜欢的字符串 pp。他找出了 pp 在 ss 中所有出现的位置 x1<x2<⋯<xkx_1 < x_2 < \dots < x_k。更准确地说,对每个 xix_i(其中 1≤i≤k1 \le i \le k),都满足条件:

sxisxi+1…sxi+∣p∣−1=p.s_{x_i} s_{x_i+1} \dots s_{x_i + |p| - 1} = p.

接着,马莱卡斯将序列 x1,x2,…,xkx_1, x_2, \dots, x_k 的某个子序列(可能为空,即什么也没写)写在一张纸上。这里,序列 bb 是序列 aa 的子序列,当且仅当可以通过从 aa 中删除若干(可能为零个或全部)元素得到 bb。

塔瓦斯醒来后,马莱卡斯把上述所有事情告诉了他。塔瓦斯已记不清原始字符串 ss,但他知道 pp 和 ss 都仅由小写英文字母组成,并且他还保留着写在纸上的那个子序列。

塔瓦斯想知道:满足条件的字符串 ss 有多少种可能?他先问了萨达斯,但萨达斯不够聪明,解不出这个问题。因此,塔瓦斯请你来帮他计算这个数目。

答案可能非常大,因此塔瓦斯希望你输出答案对 109+710^9 + 7 取模的结果。

输入格式

The first line contains two integers n and m, the length of s and the length of the subsequence Malekas wrote down (1 ≤ n ≤ 106 and 0 ≤ m ≤ n - |p| + 1).

The second line contains string p (1 ≤ |p| ≤ n).

The next line contains m space separated integers _y_1, _y_2, ..., y__m, Malekas' subsequence (1 ≤ _y_1 < _y_2 < ... < y__m ≤ n - |p| + 1).

第一行包含两个整数 nn 和 mm,分别表示字符串 ss 的长度以及 Malekas 所记录的子序列的长度(1≤n≤1061 \leq n \leq 10^6,且 0≤m≤n−∣p∣+10 \leq m \leq n - |p| + 1)。

第二行包含字符串 pp(1≤∣p∣≤n1 \leq |p| \leq n)。

下一行包含 mm 个以空格分隔的整数 y1, y2, …, ymy_1,\ y_2,\ \dots,\ y_m,即 Malekas 的子序列(1≤y1<y2<⋯<ym≤n−∣p∣+11 \leq y_1 < y_2 < \dots < y_m \leq n - |p| + 1)。

输出格式

In a single line print the answer modulo 1000 000 007.

在一行中输出答案对 1000 000 007 取模的结果。

输入输出样例

  • 输入#1

    6 2
    ioi
    1 3

    输出#1

    26
  • 输入#2

    5 2
    ioi
    1 2

    输出#2

    0

说明/提示

In the first sample test all strings of form "ioioi?" where the question mark replaces arbitrary English letter satisfy.

Here |x| denotes the length of string x.

Please note that it's possible that there is no such string (answer is 0).

在第一个样例测试中,所有形如 "ioioi?" 的字符串均满足条件,其中问号 ? 可替换为任意英文字母。

这里 ∣x∣|x| 表示字符串 xx 的长度。

请注意,可能不存在满足条件的字符串(此时答案为 0)。

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

首页