E - Stamp Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 475475

問題文

英大文字からなる長さ NN の文字列 SS と、英大文字からなる長さ M (N)M\ (\leq N) の文字列 TT が与えられます。

# のみからなる長さ NN の文字列 XX があります。 以下の操作を好きな回数行うことで、XXSS に一致させることができるか判定してください。

  • XX の中から連続する MM 文字を選び、TT で置き換える。

制約

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Mmin(N,1 \leq M \leq \min(N, 55))
  • SS は英大文字からなる長さ NN の文字列
  • TT は英大文字からなる長さ MM の文字列

入力

入力は以下の形式で標準入力から与えられる。

NN MM
SS
TT

出力

XXSS に一致させることができるならば Yes を、できないならば No を出力せよ。


入力例 1Copy

Copy
7 3
ABCBABC
ABC

出力例 1Copy

Copy
Yes

以下、XXll 文字目から rr 文字目までの部分を X[l:r]X[l:r] と表記します。

次のように操作を行うことで、XXSS に一致させることができます。

  1. X[3:5]X[3:5]TT で置き換える。X=X= ##ABC## になる。 
  2. X[1:3]X[1:3]TT で置き換える。X=X= ABCBC## になる。 
  3. X[5:7]X[5:7]TT で置き換える。X=X= ABCBABC になる。 

入力例 2Copy

Copy
7 3
ABBCABC
ABC

出力例 2Copy

Copy
No

どのように操作を行っても、XXSS に一致させることはできません。


入力例 3Copy

Copy
12 2
XYXXYXXYYYXY
XY

出力例 3Copy

Copy
Yes

Score : 475475 points

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 1Copy

Copy
7 3
ABCBABC
ABC

Sample Output 1Copy

Copy
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##.
  3. Replace X[5:7]X[5:7] with TT. XX becomes ABCBABC.

Sample Input 2Copy

Copy
7 3
ABBCABC
ABC

Sample Output 2Copy

Copy
No

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


Sample Input 3Copy

Copy
12 2
XYXXYXXYYYXY
XY

Sample Output 3Copy

Copy
Yes


2025-04-24 (Thu)
17:07:29 +00:00