#abc259c. C - XX to XXX

C - XX to XXX

Score : 300300 points

问题描述

给定两个字符串 SSTT。确定是否可以通过执行以下操作一定次数(可能为零次)来使 SS 等于 TT

SS 中任意两个连续相等的字符之间插入一个与这些字符相等的字符。具体步骤如下:

  1. NN 为当前字符串 SS 的长度,即 S=S1S2SNS = S_1S_2\ldots S_N
  2. 选择一个整数 ii,满足 1iN11 \leq i \leq N-1(包含两端点),且 Si=Si+1S_i = S_{i+1}。(如果没有这样的 ii,则无需进行任何操作,并立即终止该操作,跳过步骤3。)
  3. SS 的第 ii 个和第 (i+1)(i+1) 个字符之间插入一个与 Si(=Si+1)S_i(= S_{i+1}) 相同的字符副本。现在,SS 变为长度为 N+1N+1 的字符串:S1S2SiSiSi+1SNS_1S_2\ldots S_i S_i S_{i+1} \ldots S_N

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

Problem Statement

You are given two strings SS and TT. Determine whether it is possible to make SS equal TT by performing the following operation some number of times (possibly zero).

Between two consecutive equal characters in SS, insert a character equal to these characters. That is, take the following three steps.

  1. Let NN be the current length of SS, and S=S1S2SNS = S_1S_2\ldots S_N.
  2. Choose an integer ii between 11 and N1N-1 (inclusive) such that Si=Si+1S_i = S_{i+1}. (If there is no such ii, do nothing and terminate the operation now, skipping step 3.)
  3. Insert a single copy of the character Si(=Si+1)S_i(= S_{i+1}) between the ii-th and (i+1)(i+1)-th characters of SS. Now, SS is a string of length N+1N+1: S1S2SiSiSi+1SNS_1S_2\ldots S_i S_i S_{i+1} \ldots S_N.

Constraints

  • Each of SS and TT is a string of length between 22 and 2×1052 \times 10^5 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS

TT

Output

If it is possible to make SS equal TT, print Yes; otherwise, print No. Note that the judge is case-sensitive.

Sample Input 1

abbaac
abbbbaaac

Sample Output 1

Yes

You can make S=S = abbaac equal T=T = abbbbaaac by the following three operations.

  • First, insert b between the 22-nd and 33-rd characters of SS. Now, S=S = abbbaac.
  • Next, insert b again between the 22-nd and 33-rd characters of SS. Now, S=S = abbbbaac.
  • Lastly, insert a between the 66-th and 77-th characters of SS. Now, S=S = abbbbaaac.

Thus, Yes should be printed.

Sample Input 2

xyzz
xyyzz

Sample Output 2

No

No sequence of operations makes S=S = xyzz equal T=T = xyyzz. Thus, No should be printed.

update @ 2024/3/10 10:59:26