답안 #626525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626525 2022-08-11T13:59:38 Z hspark8494 Type Printer (IOI08_printer) Python 3
0 / 100
18 ms 2948 KB
class trie:
    def __init__(self, parent):
        self.data = {}
        self.parent = parent
        self.len = 0
        self.end = False

words = []

tries = trie(None)
n = int(input())
for _ in range(n):
    word = input()
    words.append(word)
    curr = tries
    ln = len(word)
    for w in word:
        if not w in curr.data:
            curr.data[w] = trie(curr)
        curr = curr.data[w]
        curr.len = max(ln, len)
    else:
        curr.end = True


def dfs_trie(curr:trie, result):
    global n
    if curr.end:
        result.append("P")
        n -= 1
    for c in sorted(curr.data.keys(), key=lambda x: curr.data[x].len):
        result.append(c)
        dfs_trie(curr.data[c], result)
    if n>0:
        result.append("-")
result = []
dfs_trie(tries, result)

print(len(result))
print(*result, sep="\n")
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 2900 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 2900 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 2844 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2900 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 2864 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 2948 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2900 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 2848 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 2880 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -