Skip to content

Commit e96493a

Browse files
author
hangyeol
committed
112차 2번 문제풀이
1 parent e5bcdbb commit e96493a

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
import sys
2+
sys.setrecursionlimit(10**7)
23

34
def main():
45
input = sys.stdin.readline
5-
S = str(input().strip())
6-
T = str(input().strip())
6+
S = input().strip()
7+
T = input().strip()
8+
found = False
79

8-
makeT(S, T)
10+
def bt(cur: str):
11+
nonlocal found
12+
if found:
13+
return
914

10-
def makeT(current, T):
11-
if len(current) > len(T):
12-
return
13-
if current == T:
14-
print(1)
15+
if len(cur) < len(S):
16+
return
1517

16-
makeT(current + 'A', T)
17-
makeT((current + 'B')[::-1], T)
18+
if len(cur) == len(S):
19+
if cur == S:
20+
found = True
21+
return
1822

23+
if cur.endswith('A'):
24+
bt(cur[:-1])
25+
26+
if cur.startswith('B'):
27+
bt(cur[1:][::-1])
28+
29+
bt(T)
30+
print(1 if found else 0)
1931

2032
if __name__ == '__main__':
2133
main()

0 commit comments

Comments
 (0)