CF314B.Sereja and Periods

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's introduce the designation , where x is a string, n is a positive integer and operation " + " is the string concatenation operation. For example, [abc, 2] = abcabc.

We'll say that string s can be obtained from string t, if we can remove some characters from string t and obtain string s. For example, strings ab and aсba can be obtained from string xacbac, and strings bx and aaa cannot be obtained from it.

Sereja has two strings, w = [a, b] and q = [c, d]. He wants to find such maximum integer p (p > 0), that [q, p] can be obtained from string w.

我们定义符号 ,其中 xx 是一个字符串,nn 是一个正整数,而运算 “ + ” 表示字符串连接操作。例如,[abc, 2]=abcabc[abc,\,2] = abcabc。

我们称字符串 ss 可由字符串 tt 得到,当且仅当我们能从字符串 tt 中删除若干字符(可以是零个或多个),从而得到字符串 ss。例如,字符串 abab 和 acbaacba 均可由字符串 xacbacxacbac 得到,而字符串 bxbx 和 aaaaaa 则无法由它得到。

Sereja 有两个字符串:w=[a, b]w = [a,\,b] 和 q=[c, d]q = [c,\,d]。他希望找出满足条件的最大正整数 pp,使得 [q, p][q,\,p] 可由字符串 ww 得到。

输入格式

The first line contains two integers b, d (1 ≤ b, d ≤ 107). The second line contains string a. The third line contains string c. The given strings are not empty and consist of lowercase English letters. Their lengths do not exceed 100.

第一行包含两个整数 bb、dd(1 ≤ b, d ≤ 1071 \le b,\,d \le 10^7)。
第二行包含字符串 aa。
第三行包含字符串 cc。
给定的字符串非空,且仅由小写英文字母组成。它们的长度均不超过 100100。

输出格式

In a single line print an integer — the largest number p. If the required value of p doesn't exist, print 0.

在一行中输出一个整数——最大的数 pp。如果所需的 pp 值不存在,则输出 0。

输入输出样例

  • 输入#1

    10 3
    abab
    bab

    输出#1

    3

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

首页