CF1909G.Pumping Lemma
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tanchiky & Siromaru - Crystal Gravity
⠀
You are given two strings s , t of length n , m , respectively. Both strings consist of lowercase letters of the English alphabet.
Count the triples (x,y,z) of strings such that the following conditions are true:
- s=x+y+z (the symbol + represents the concatenation);
- t=x+k timesy+⋯+y+z for some integer k .
输入格式
The first line contains two integers n and m ( 1≤n<m≤107 ) — the length of the strings s and t , respectively.
The second line contains the string s of length n , consisting of lowercase letters of the English alphabet.
The third line contains the string t of length m , consisting of lowercase letters of the English alphabet.
输出格式
Output a single integer: the number of valid triples (x,y,z) .
输入输出样例
输入#1
4 8 abcd abcbcbcd
输出#1
1
输入#2
3 5 aaa aaaaa
输出#2
5
输入#3
12 16 abbababacaab abbababababacaab
输出#3
8
说明/提示
In the first test case, the only valid triple is (x,y,z)=("a","bc","d") . In fact,
- "abcd"="a"+"bc"+"d" ;
- "abcbcbcd"="a"+"bc"+"bc"+"bc"+"d" .
In the second test case, there are 5 valid triples:
- (x,y,z)=("","a","aa") ;
- (x,y,z)=("","aa","a") ;
- (x,y,z)=("a","a","a") ;
- (x,y,z)=("a","aa","") ;
- (x,y,z)=("aa","a","") .
In the third test case, there are 8 valid triples:
- (x,y,z)=("ab","ba","babacaab") ;
- (x,y,z)=("abb","ab","abacaab") ;
- (x,y,z)=("abba","ba","bacaab") ;
- (x,y,z)=("ab","baba","bacaab") ;
- (x,y,z)=("abbab","ab","acaab") ;
- (x,y,z)=("abb","abab","acaab") ;
- (x,y,z)=("abbaba","ba","caab") ;
- (x,y,z)=("abba","baba","caab") .