#abc346f. F - SSttrriinngg in StringString
F - SSttrriinngg in StringString
Score: points
问题陈述
对于长度为 的字符串 ,让 表示通过重复字符串 来获得的字符串 次,让 表示通过重复字符串 的第一个字符、第二个字符、、第 个字符,按此顺序来获得的字符串 次。例如,如果 abc,则 abcabc,而 aaabbbccc。此外,对于任何字符串 , 和 都是空字符串。
给定一个正整数 和字符串 和 。找到最大的非负整数 ,使得 是 的(不一定是连续的)子序列。请注意,根据定义, 总是 的子序列。
什么是子序列?一个字符串 的(不一定是连续的)子序列是通过从 中删除零个或多个字符,然后不改变顺序地连接剩余元素而获得的字符串。例如,ac、atcoder 和(空字符串)都是 atcoder 的子序列,但 ta 不是。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
For a string of length , let denote the string obtained by repeating times the string , and denote the string obtained by repeating times the first character, the second character, , the -th character of , in this order. For example, if abc, then abcabc, and aaabbbccc. Also, for any string , both and are empty strings.
You are given a positive integer and strings and . Find the largest non-negative integer such that is a (not necessarily contiguous) subsequence of . Note that is always a subsequence of by definition.
What is a subsequence? A (not necessarily contiguous) subsequence of a string is a string obtained by removing zero or more characters from and then concatenating the remaining elements without changing the order. For example, ac, atcoder, and (empty string) are all subsequences of atcoder, but ta is not.
Constraints
- is an integer.
- and are strings consisting of lowercase English letters with lengths between and , inclusive.
Input
The input is given from Standard Input in the following format:
Output
Print the largest non-negative integer such that is a (not necessarily contiguous) subsequence of .
Sample Input 1
3
abc
ab
Sample Output 1
2
We have abcabcabc. aabb is a subsequence of , but aaabbb is not, so print .
Sample Input 2
3
abc
arc
Sample Output 2
0
Sample Input 3
1000000000000
kzazkakxkk
azakxk
Sample Output 3
344827586207
update @ 2024/5/16 17:18:22