#x1004. CFMessenger
CFMessenger
Messenger
题面翻译
题目描述 给你两个字符串s,t,求出t在s中出现了多少次。
这两个字符串可能会很长,所以字符串被分成很多块,其中s被分成n块,t被分成m块。每一块(l,c)代表l个c字符连接在一起组成的字符串。即(2,′a′)="aa"。一个字符串ss会被表示成一个序列((l1,c1),(l2,c2),…,(ln,cn))。在输入中字符串"l−c"代表(l,c)。
注意到字符串的表示方式不是唯一的,例如((1,′a′),(3,′a′))=((2,′a′),(2,′a′))="aaaa"。
输入格式 第一行有两个整数n,m;
第二行有n个块,表示字符串s。
第三行有m个块,表示字符串t。
输出格式 一行一个整数:答案。
感谢@ezoixx130 提供的翻译
题目描述
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of blocks, each block containing only equal characters. One block may be described as a pair , where is the length of the -th block and is the corresponding letter. Thus, the string may be written as the sequence of pairs .
Your task is to write the program, that given two compressed string and finds all occurrences of in . Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that is the starting position of some occurrence of in if and only if , where is the -th character of string .
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as ,
,
...
输入格式
The first line of the input contains two integers and ( ) — the number of blocks in the strings and , respectively.
The second line contains the descriptions of parts of string in the format " - " ( ) — the length of the -th part and the corresponding lowercase English letter.
The second line contains the descriptions of parts of string in the format " - " ( ) — the length of the -th part and the corresponding lowercase English letter.
输出格式
Print a single integer — the number of occurrences of in .
样例 #1
样例输入 #1
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
样例输出 #1
1
样例 #2
样例输入 #2
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
样例输出 #2
6
样例 #3
样例输入 #3
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
样例输出 #3
0
提示
In the first sample, = "aaabbccccaaacc", and string = "aabbc". The only occurrence of string in string starts at position .
In the second sample, = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and = "aaa". The occurrences of in start at positions , , , , and .