A8786 | Colorful Stones
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are two sequences of colorful stones. The color of each stone is one of red, green, or blue. You are given two strings $s$ and $t$ . The $i$ -th (1-based) character of $s$ represents the color of the $i$ -th stone of the first sequence. Similarly, the $i$ -th (1-based) character of $t$ represents the color of the $i$ -th stone of the second sequence. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone of the first sequence and Cat Vasya is standing on the first stone of the second sequence. You can perform the following instructions zero or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction $c$ , the animals standing on stones whose colors are $c$ will move one stone forward. For example, if you perform an instruction «RED», the animals standing on red stones will move one stone forward. You are not allowed to perform instructions that lead some animals out of the sequences. In other words, if some animals are standing on the last stones, you can't perform the instructions of the colors of those stones.
A pair of positions (position of Liss, position of Vasya) is called a state. A state is called reachable if the state is reachable by performing instructions zero or more times from the initial state (1, 1). Calculate the number of distinct reachable states.
Initially Squirrel Liss is standing on the first stone of the first sequence and Cat Vasya is standing on the first stone of the second sequence. You can perform the following instructions zero or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction $c$ , the animals standing on stones whose colors are $c$ will move one stone forward. For example, if you perform an instruction «RED», the animals standing on red stones will move one stone forward. You are not allowed to perform instructions that lead some animals out of the sequences. In other words, if some animals are standing on the last stones, you can't perform the instructions of the colors of those stones.
A pair of positions (position of Liss, position of Vasya) is called a state. A state is called reachable if the state is reachable by performing instructions zero or more times from the initial state (1, 1). Calculate the number of distinct reachable states.
输入格式
The input contains two lines. The first line contains the string $s$ ( $1<=|s|<=10^{6}$ ). The second line contains the string $t$ ( $1<=|t|<=10^{6}$ ). The characters of each string will be one of "R", "G", or "B".
输出格式
Print the number of distinct reachable states in a single line.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
输入输出样例
输入 #1
RBR RGG
输出 #1
5
输入 #2
RGBB BRRBRR
输出 #2
19
输入 #3
RRRRRRRRRR RRRRRRRR
输出 #3
8
In the first example, there are five reachable states: (1, 1), (2, 2), (2, 3), (3, 2), and (3, 3). For example, the state (3, 3) is reachable because if you perform instructions "RED", "GREEN", and "BLUE" in this order from the initial state, the state will be (3, 3). The following picture shows how the instructions work in this case.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted