We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e5bcdbb commit e96493aCopy full SHA for e96493a
1 file changed
live11/test112/문제2/백한결.py
@@ -1,21 +1,33 @@
1
import sys
2
+sys.setrecursionlimit(10**7)
3
4
def main():
5
input = sys.stdin.readline
- S = str(input().strip())
6
- T = str(input().strip())
+ S = input().strip()
7
+ T = input().strip()
8
+ found = False
9
- makeT(S, T)
10
+ def bt(cur: str):
11
+ nonlocal found
12
+ if found:
13
+ return
14
-def makeT(current, T):
- if len(current) > len(T):
- return
- if current == T:
- print(1)
15
+ if len(cur) < len(S):
16
17
- makeT(current + 'A', T)
- makeT((current + 'B')[::-1], T)
18
+ if len(cur) == len(S):
19
+ if cur == S:
20
+ found = True
21
22
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)
31
32
if __name__ == '__main__':
33
main()
0 commit comments