Submission #1079948

#TimeUsernameProblemLanguageResultExecution timeMemory
1079948xinyubb2000Type Printer (IOI08_printer)Cpython 3
0 / 100
882 ms64816 KiB
class TrieNode: def __init__(self): self.children = {} self.is_end_of_word = False self.depth = 0 class Trie: def __init__(self): self.root = TrieNode() def insert(self, word: str) -> None: node = self.root for char in word: if char not in node.children: node.children[char] = TrieNode() node = node.children[char] node.is_end_of_word = True def starts_with(self, prefix: str) -> bool: node = self.root for char in prefix: if char not in node.children: return False node = node.children[char] return True # import sys # sys.stdin = open('1.in', 'r') trie = Trie() n = int(input()) for _ in range(n): word = input() trie.insert(word) cnt = 0 def dfs1(node): depth = 0 for child in node.children.values(): depth = max(depth, dfs1(child)) node.depth = depth + 1 return node.depth def dfs2(node): if node.is_end_of_word: print('P') global cnt cnt += 1 if cnt == n: exit() for char, child in sorted(node.children.items(), key=lambda item: item[1].depth): print(char) dfs2(child) print('-') dfs1(trie.root) dfs2(trie.root)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...