A8614 | Little Elephant and Retro Strings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Little Elephant has found a ragged old black-and-white string $s$ on the attic.
The characters of string $s$ are numbered from the left to the right from $1$ to $|s|$ , where $|s|$ is the length of the string. Let's denote the $i$ -th character of string $s$ as $s_{i}$ . As the string is black-and-white, each character of the string is either letter "B", or letter "W". Unfortunately, the string is very old and some characters are damaged. The damaged positions are denoted as "X".
The Little Elephant in determined to restore the string and hang it on the wall. For that he needs to replace each character "X" by a "B" or a "W". The string must look good on the wall, so it must be beautiful. The Little Elephant considers a string beautiful if it has two non-intersecting substrings of a given length $k$ , such that the left one fully consists of characters "B", and the right one fully consists of characters "W". More formally, there are four integers $a,b,c,d$ $(1<=a<=b<c<=d<=|s|; b-a+1=d-c+1=k)$ such that $s_{i}$ = "B" $(a<=i<=b)$ and $s_{j}$ = "W" $(c<=j<=d)$ .
Help the Little Elephant find the number of different beautiful strings he can obtain from string $s$ . Two strings are considered different if there is such position, where the character in the first string differs from the corresponding character in the second string. If this string doesn't contain characters «X» and it is already beautiful — the answer is 1.
As the answer can be rather large, print it modulo $1000000007$ $(10^{9}+7)$ .
The characters of string $s$ are numbered from the left to the right from $1$ to $|s|$ , where $|s|$ is the length of the string. Let's denote the $i$ -th character of string $s$ as $s_{i}$ . As the string is black-and-white, each character of the string is either letter "B", or letter "W". Unfortunately, the string is very old and some characters are damaged. The damaged positions are denoted as "X".
The Little Elephant in determined to restore the string and hang it on the wall. For that he needs to replace each character "X" by a "B" or a "W". The string must look good on the wall, so it must be beautiful. The Little Elephant considers a string beautiful if it has two non-intersecting substrings of a given length $k$ , such that the left one fully consists of characters "B", and the right one fully consists of characters "W". More formally, there are four integers $a,b,c,d$ $(1<=a<=b<c<=d<=|s|; b-a+1=d-c+1=k)$ such that $s_{i}$ = "B" $(a<=i<=b)$ and $s_{j}$ = "W" $(c<=j<=d)$ .
Help the Little Elephant find the number of different beautiful strings he can obtain from string $s$ . Two strings are considered different if there is such position, where the character in the first string differs from the corresponding character in the second string. If this string doesn't contain characters «X» and it is already beautiful — the answer is 1.
As the answer can be rather large, print it modulo $1000000007$ $(10^{9}+7)$ .
输入格式
The first line contains two space-separated integers $n$ and $k$ $(1<=k<=n<=10^{6})$ . The second line contains string $s$ . String $s$ has length $n$ and only consists of characters "W", "B" and "X".
输出格式
On a single line print an integer — the answer to the problem modulo $1000000007$ $(10^{9}+7)$ .
输入输出样例
输入 #1
3 2 XXX
输出 #1
0
输入 #2
4 2 XXXX
输出 #2
1
输入 #3
10 2 XXBXXWXXXX
输出 #3
166
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted