#B. CS240 project Problem 2

    传统题 1000ms 256MiB

CS240 project Problem 2

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

You are presented with two primary strings: S and T, and a target string X of the same length as S, initially filled entirely with the character #. Your task is to determine if it's possible to transform X into S by repeatedly overlaying the string T onto X.

Constraints

  • The string S is composed of letters and has a length N.
  • The string T also consists of letters and has a length M, where M is less than or equal to N.
  • X is a string of length N filled entirely with the character #.
  • You can overlay T on any part of X, replacing M consecutive characters, as many times as you want.
  • Given lengths: 1N2×1051 ≤ N ≤ 2×10^5 and 1Mmin(N,5)1 ≤ M ≤ min(N, 5).

Input

The input is given from Standard Input in the following format:

N M
S
T

Output

Print Yes if it is possible to make X match S; print No otherwise.

Sample Input 1

5 3
ABCBC
ABC

Sample Output 1

Yes

Below, let X[l:r]X[l:r] denote the part from the ll-th through the rr-th character of XX.

You can make XX match SS by operating as follows.

  1. Replace X[3:5]X[3:5] with TT. XX becomes ##ABC.
  2. Replace X[1:3]X[1:3] with TT. XX becomes ABCBC.

Sample Input 2

7 3
ABBCABC
ABC

Sample Output 2

No

it's impossible to make XX match SS.

Sample Input 3

12 2
XYXXYXXYYYXY
XY

Sample Output 3

Yes

CS240 2024 Spring Project Problem

未参加
状态
已结束
规则
IOI
题目
4
开始于
2024-5-30 17:00
结束于
2024-6-24 23:59
持续时间
607 小时
主持人
参赛人数
99