CF1909G.Pumping Lemma

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

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+⋯+y⏟k times+zt = x+\underbrace{ y+\dots+y }_{k \text{ times}} + z for some integer kk.

Tanchiky & Siromaru - Crystal Gravity

⠀

给定两个字符串 ss 和 tt,长度分别为 nn 和 mm。两个字符串均由小写英文字母组成。

统计满足以下条件的字符串三元组 (x,y,z)(x, y, z) 的个数:

  • s=x+y+zs = x+y+z(其中符号 ++ 表示字符串连接);
  • t=x+y+⋯+y⏟k 次+zt = x+\underbrace{ y+\dots+y }_{k \text{ 次}} + z,其中 kk 为某个整数。

输入格式

The first line contains two integers nn and mm (1≤n<m≤1071 \leq n \lt 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.

第一行包含两个整数 nn 和 mm(1≤n<m≤1071 \leq n \lt m \leq 10^7)—— 分别为字符串 ss 和 tt 的长度。

第二行包含一个长度为 nn 的字符串 ss,由小写英文字母组成。

第三行包含一个长度为 mm 的字符串 tt,由小写英文字母组成。

输出格式

Output a single integer: the number of valid triples (x,y,z)(x, y, z).

输出一个整数:满足条件的三元组 (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"}).

在第一个测试用例中,唯一有效的三元组是 (x,y,z)=("a","bc","d")(x, y, z) = (\texttt{"a"}, \texttt{"bc"}, \texttt{"d"})。事实上,

  • "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"}。

在第二个测试用例中,共有 55 个有效的三元组:

  • (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{""})。

在第三个测试用例中,共有 88 个有效的三元组:

  • (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"})。

输入解题思路,AI测评打分。不知道怎么写?

首页