Skip to content

Commit 734ef09

Browse files
authored
Merge pull request #716 from baekhangyeol/main
[백한결] 112차 라이브 코테 제출
2 parents 33bc970 + e96493a commit 734ef09

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
3+
def main():
4+
input = sys.stdin.readline
5+
N = int(input())
6+
7+
for i in range(N):
8+
word = str(input().strip())
9+
10+
word = sorted(list(word))
11+
12+
result = []
13+
backtracking(word, [], [False] * len(word), result)
14+
15+
for r in result:
16+
print(r)
17+
18+
def backtracking(word, path, visited, result):
19+
if len(path) == len(word):
20+
result.append("".join(path))
21+
return
22+
23+
for i in range(len(word)):
24+
if visited[i]:
25+
continue
26+
if i > 0 and word[i] == word[i-1] and not visited[i-1]:
27+
continue
28+
29+
visited[i] = True
30+
path.append(word[i])
31+
backtracking(word, path, visited, result)
32+
path.pop()
33+
visited[i] = False
34+
35+
if __name__ == '__main__':
36+
main()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
sys.setrecursionlimit(10**7)
3+
4+
def main():
5+
input = sys.stdin.readline
6+
S = input().strip()
7+
T = input().strip()
8+
found = False
9+
10+
def bt(cur: str):
11+
nonlocal found
12+
if found:
13+
return
14+
15+
if len(cur) < len(S):
16+
return
17+
18+
if len(cur) == len(S):
19+
if cur == S:
20+
found = True
21+
return
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

Comments
 (0)