CF1881A.Don't Try to Count

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given a string xx of length nn and a string ss of length mm (n⋅m≤25n \cdot m \le 25), consisting of lowercase Latin letters, you can apply any number of operations to the string xx.

In one operation, you append the current value of xx to the end of the string xx. Note that the value of xx will change after this.

For example, if x=x ="aba", then after applying operations, xx will change as follows: "aba" →\rightarrow "abaaba" →\rightarrow "abaabaabaaba".

After what minimum number of operations ss will appear in xx as a substring? A substring of a string is defined as a contiguous segment of it.

给定一个长度为 nn 的字符串 xx 和一个长度为 mm 的字符串 ss(满足 n⋅m≤25n \cdot m \le 25),二者均由小写拉丁字母组成。你可以对字符串 xx 执行任意次数的操作。

每次操作中,你将当前的 xx 追加到 xx 的末尾。注意:执行该操作后,xx 的值会发生变化。

例如,若 x=x = "aba",则执行操作后,xx 的变化过程如下:"aba" →\rightarrow "abaaba" →\rightarrow "abaabaabaaba"。

最少需要多少次操作,才能使 ss 作为子串出现在 xx 中?字符串的子串定义为该字符串中的一段连续字符序列。

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two numbers nn and mm (1≤n⋅m≤251 \le n \cdot m \le 25) — the lengths of strings xx and ss, respectively.

The second line of each test case contains the string xx of length nn.

The third line of each test case contains the string ss of length mm.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n⋅m≤251 \le n \cdot m \le 25)—— 分别表示字符串 xx 和 ss 的长度。

每个测试用例的第二行包含长度为 nn 的字符串 xx。

每个测试用例的第三行包含长度为 mm 的字符串 ss。

输出格式

For each test case, output a single number — the minimum number of operations after which ss will appear in xx as a substring. If this is not possible, output −1-1.

对于每个测试用例,输出一个整数——使得字符串 ss 作为子串出现在字符串 xx 中所需的最少操作次数。如果无法实现,则输出 −1-1。

输入输出样例

  • 输入#1

    12
    1 5
    a
    aaaaa
    5 5
    eforc
    force
    2 5
    ab
    ababa
    3 5
    aba
    ababa
    4 3
    babb
    bbb
    5 1
    aaaaa
    a
    4 2
    aabb
    ba
    2 8
    bk
    kbkbkbkb
    12 2
    fjdgmujlcont
    tf
    2 2
    aa
    aa
    3 5
    abb
    babba
    1 19
    m
    mmmmmmmmmmmmmmmmmmm

    输出#1

    3
    1
    2
    -1
    1
    0
    1
    3
    1
    0
    2
    5

说明/提示

In the first test case of the example, after 22 operations, the string will become "aaaa", and after 33 operations, it will become "aaaaaaaa", so the answer is 33.

In the second test case of the example, after applying 11 operation, the string will become "eforceforc\text{e}\color{red}{\text{force}}\text{forc}", where the substring is highlighted in red.

In the fourth test case of the example, it can be shown that it is impossible to obtain the desired string as a substring.

在示例的第一个测试用例中,经过 22 次操作后,字符串将变为 "aaaa";经过 33 次操作后,它将变为 "aaaaaaaa",因此答案为 33。

在示例的第二个测试用例中,执行 11 次操作后,字符串将变为 "eforceforc\text{e}\color{red}{\text{force}}\text{forc}",其中子串以红色高亮显示。

在示例的第四个测试用例中,可以证明无法使目标字符串作为子串出现。

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

首页