This documentation is automatically generated by online-judge-tools/verification-helper
Trie()
空の Trie 木を初期構築する。計算量 $O(1)$
search(string: str) -> bool
長さ $S$ の文字列 string
が Trie 木に存在しているかどうかを返す。計算量 $O(S)$
insert(string: str) -> bool
長さ $S$ の文字列 string
を Trie 木に追加する。追加に成功した場合は True
を、失敗した場合 (既に string
が Trie 木に存在していた場合) は False
を返す。計算量 $O(S)$
delete(string: str) -> bool
長さ $S$ の文字列 string
を Trie 木から削除する。削除に成功した場合は True
を、失敗した場合 (string
が Trie 木に存在していなかった場合) は False
を返す。計算量 $O(S)$
class TrieNode:
def __init__(self):
self.child = {}
self.valid = False
def set_child(self, s):
self.child[s] = TrieNode()
def get_child(self, s):
if s not in self.child:
return None
return self.child[s]
class Trie:
def __init__(self):
self.root = TrieNode()
def search(self, string):
ptr = self.root
for s in string:
if ptr.get_child(s) is None:
return False
ptr = ptr.get_child(s)
return ptr.valid
def insert(self, string):
ptr = self.root
for s in string:
if ptr.get_child(s) is None:
ptr.set_child(s)
ptr = ptr.get_child(s)
if ptr.valid:
return False
ptr.valid = True
return True
def delete(self, string):
ptr = self.root
for s in string:
if ptr.get_child(s) is None:
return False
ptr = ptr.get_child(s)
ptr.valid = False
return True
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
raise NotImplementedError
NotImplementedError