AtCoder Beginner Contest 259 - C - XX to XXX
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : points
Problem Statement
You are given two strings and . Determine whether it is possible to make equal by performing the following operation some number of times (possibly zero).
Between two consecutive equal characters in , insert a character equal to these characters. That is, take the following three steps.
- Let be the current length of , and .
- Choose an integer between and (inclusive) such that . (If there is no such , do nothing and terminate the operation now, skipping step 3.)
- Insert a single copy of the character between the -th and -th characters of . Now, is a string of length : .
Constraints
- Each of and is a string of length between and (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to make equal , print Yes
; otherwise, print No
.
Note that the judge is case-sensitive.
Sample Input 1
abbaac abbbbaaac
Sample Output 1
Yes
You can make abbaac
equal abbbbaaac
by the following three operations.
- First, insert
b
between the -nd and -rd characters of . Now,abbbaac
. - Next, insert
b
again between the -nd and -rd characters of . Now,abbbbaac
. - Lastly, insert
a
between the -th and -th characters of . Now,abbbbaaac
.
Thus, Yes
should be printed.
Sample Input 2
xyzz xyyzz
Sample Output 2
No
No sequence of operations makes xyzz
equal xyyzz
.
Thus, No
should be printed.
题目大意
你可以在字符串$S$的连续两个相同的字母变成连续且相同的三个字母
通俗地讲,就是$..aa.$能变成$..aaa.$
问你$S$串能否变成$T$
解题思路
用双指针分别记录$S$和$T$处理到了那个字母。(分别记为$locS$和$locT$)
如果$S$和$T$对应的字母相同,则两个指针分别向后移动一位
1 |
|
否则($S$和$T$对应的元素不同),要想使得$S$变成$T$就需要在$S$中插入一个字母$T[locT]$
要想在$S$的$locS$处插入一个字母$T[locT]$,就需要$S[loc-1]、S[loc-2]$都为$T[locT]$。(因为已知$S[locS] \neq T[locT]$,所以新插入的字母不可能通过$S[locS]、S[locS + 1]$拓展出来)
- 如果$S[loc-1]、S[loc-2]$都为$T[locT]$,就$locT++$($T$的$locT$已由$S[loc-1]、S[loc-2]$拓展出来)
- 否则,直接输出
No
并结束即可。
AC代码
1 |
|
同步发文于CSDN,原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/125700254