#abc329e. E - Stamp

E - Stamp

Score : 475475 points

问题描述

你已知两个字符串:SS,由大写英文字母组成,长度为 NN;以及 TT,同样由大写英文字母组成,长度为 M (N)M\ (\leq N)

存在一个长度为 NN 的字符串 XX,仅由字符 # 组成。请确定是否可以通过执行以下操作任意次数,使 XXSS 匹配:

  • XX 中选择连续的 MM 个字符,并用 TT 替换它们。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two strings: SS, which consists of uppercase English letters and has length NN, and TT, which also consists of uppercase English letters and has length M (N)M\ (\leq N).

There is a string XX of length NN consisting only of the character #. Determine whether it is possible to make XX match SS by performing the following operation any number of times:

  • Choose MM consecutive characters in XX and replace them with TT.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Mmin(N,1 \leq M \leq \min(N, 55))
  • SS is a string consisting of uppercase English letters with length NN.
  • TT is a string consisting of uppercase English letters with length MM.

Input

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

NN MM

SS

TT

Output

Print Yes if it is possible to make XX match SS; print No otherwise.

Sample Input 1

7 3
ABCBABC
ABC

Sample Output 1

Yes

Below, let 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\] with TT. XX becomes ##ABC##.
  2. Replace X\[1:3\] with TT. XX becomes ABCBC##.
  3. Replace X\[5:7\] with TT. XX becomes ABCBABC.

Sample Input 2

7 3
ABBCABC
ABC

Sample Output 2

No

No matter how you operate, it is impossible to make XX match SS.

Sample Input 3

12 2
XYXXYXXYYYXY
XY

Sample Output 3

Yes

update @ 2024/3/10 01:54:27