728x90
계속 시간 초과가 나서 고민을 해보고 B에서 A로 반대로 차근차근 만들어 주었더니 풀렸다.
from collections import deque
from itertools import combinations
import sys
a = input()
b = input()
queue = [ ]
queue.append(a)
for i in range(len(list(b))-len(list(a))):
if b[-1]=='A':
b = b[0:len(list(b))-1]
else:
b = b[0:len(list(b))-1][::-1]
if b==a:
print('1')
else:
print('0')
"""
temp = deque()
for j in range(0,len(queue)):
if queue[j]+'A' in b or 'A'+queue[j][::-1] in b:
temp.append(queue[j]+'A')
if queue[j][::-1]+'B' in b or 'B'+queue[j]:
temp.append(queue[j][::-1]+'B')
if b in temp:
answer = 1
break
queue = temp
"""
728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 4811 알약 (0) | 2023.04.11 |
|---|---|
| [파이썬] 백준 14179 빗물 (0) | 2023.04.10 |
| [파이썬] 백준 5582 공통 부분 문자열 (0) | 2023.04.09 |
| [파이썬] 백준 15486 퇴사 2 (1) | 2023.04.09 |
| [파이썬] 백준 1717 집합의 표현 (0) | 2023.04.08 |