E - Operate 1 Editorial
by
toam
以下のような方針で AC することができます.
- \(S\) と \(T\) がともに空でなく先頭の文字が同じである限り,両者の先頭の文字を削除する.
- \(S\) と \(T\) がともに空でなく末尾の文字が同じである限り,両者の末尾の文字を削除する.
- 上の操作の後, \(S\) と \(T\) の長さがともに \(1\) 以下のとき
Yes
を,そうでないときNo
を出力する.
K = int(input())
S = list(input())
T = list(input())
for _ in range(2):
while len(S) and len(T) and S[-1] == T[-1]:
S.pop()
T.pop()
S = S[::-1]
T = T[::-1]
if len(S) <= 1 and len(T) <= 1:
print("Yes")
else:
print("No")
posted:
last update: