CF1909G.Pumping Lemma

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Tanchiky & Siromaru - Crystal Gravity

You are given two strings ss , tt of length nn , mm , respectively. Both strings consist of lowercase letters of the English alphabet.

Count the triples (x,y,z)(x, y, z) of strings such that the following conditions are true:

  • s=x+y+zs = x+y+z (the symbol ++ represents the concatenation);
  • t=x+y++yk times+zt = x+\underbrace{ y+\dots+y }_{k \text{ times}} + z for some integer kk .

输入格式

The first line contains two integers nn and mm ( 1n<m1071 \leq n < m \leq 10^7 ) — the length of the strings ss and tt , respectively.

The second line contains the string ss of length nn , consisting of lowercase letters of the English alphabet.

The third line contains the string tt of length mm , consisting of lowercase letters of the English alphabet.

输出格式

Output a single integer: the number of valid triples (x,y,z)(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")(x, y, z) = (\texttt{"a"}, \texttt{"bc"}, \texttt{"d"}) . In fact,

  • "abcd"="a"+"bc"+"d"\texttt{"abcd"} = \texttt{"a"} + \texttt{"bc"} + \texttt{"d"} ;
  • "abcbcbcd"="a"+"bc"+"bc"+"bc"+"d"\texttt{"abcbcbcd"} = \texttt{"a"} + \texttt{"bc"} + \texttt{"bc"} + \texttt{"bc"} + \texttt{"d"} .

In the second test case, there are 55 valid triples:

  • (x,y,z)=("","a","aa")(x, y, z) = (\texttt{""}, \texttt{"a"}, \texttt{"aa"}) ;
  • (x,y,z)=("","aa","a")(x, y, z) = (\texttt{""}, \texttt{"aa"}, \texttt{"a"}) ;
  • (x,y,z)=("a","a","a")(x, y, z) = (\texttt{"a"}, \texttt{"a"}, \texttt{"a"}) ;
  • (x,y,z)=("a","aa","")(x, y, z) = (\texttt{"a"}, \texttt{"aa"}, \texttt{""}) ;
  • (x,y,z)=("aa","a","")(x, y, z) = (\texttt{"aa"}, \texttt{"a"}, \texttt{""}) .

In the third test case, there are 88 valid triples:

  • (x,y,z)=("ab","ba","babacaab")(x, y, z) = (\texttt{"ab"}, \texttt{"ba"}, \texttt{"babacaab"}) ;
  • (x,y,z)=("abb","ab","abacaab")(x, y, z) = (\texttt{"abb"}, \texttt{"ab"}, \texttt{"abacaab"}) ;
  • (x,y,z)=("abba","ba","bacaab")(x, y, z) = (\texttt{"abba"}, \texttt{"ba"}, \texttt{"bacaab"}) ;
  • (x,y,z)=("ab","baba","bacaab")(x, y, z) = (\texttt{"ab"}, \texttt{"baba"}, \texttt{"bacaab"}) ;
  • (x,y,z)=("abbab","ab","acaab")(x, y, z) = (\texttt{"abbab"}, \texttt{"ab"}, \texttt{"acaab"}) ;
  • (x,y,z)=("abb","abab","acaab")(x, y, z) = (\texttt{"abb"}, \texttt{"abab"}, \texttt{"acaab"}) ;
  • (x,y,z)=("abbaba","ba","caab")(x, y, z) = (\texttt{"abbaba"}, \texttt{"ba"}, \texttt{"caab"}) ;
  • (x,y,z)=("abba","baba","caab")(x, y, z) = (\texttt{"abba"}, \texttt{"baba"}, \texttt{"caab"}) .
首页