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

+ Recent posts