class trie:
def __init__(self, parent):
self.data = {}
self.parent = parent
self.dept = 0
self.end = False
javascript:tab_clicked(1)
from sys import stdin
input = stdin.readline
words = []
tries = trie(None)
n = int(input())
for _ in range(n):
word = input().rstrip()
words.append(word)
curr = tries
for w in word:
if not w in curr.data:
curr.data[w] = trie(curr)
curr = curr.data[w]
p = curr.parent
while p:
p.dept+=1
p = p.parent
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].dept):
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")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
2900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
2924 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
2892 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
2900 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
2904 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
2932 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
2828 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
2928 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
19 ms |
2904 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |