Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions atcoder/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ def cmp(x: int, y: int) -> int:


def _sa_is(s: typing.List[int], upper: int) -> typing.List[int]:
'''
SA-IS, linear-time suffix array construction
Reference:
G. Nong, S. Zhang, and W. H. Chan,
Two Efficient Algorithms for Linear Time Suffix Array Construction
'''

threshold_naive = 10
threshold_doubling = 40

Expand Down Expand Up @@ -165,6 +158,14 @@ def induce(lms: typing.List[int]) -> None:

def suffix_array(s: typing.Union[str, typing.List[int]],
upper: typing.Optional[int] = None) -> typing.List[int]:
'''
SA-IS, linear-time suffix array construction

Reference:
G. Nong, S. Zhang, and W. H. Chan,
Two Efficient Algorithms for Linear Time Suffix Array Construction
'''

if isinstance(s, str):
return _sa_is([ord(c) for c in s], 255)
elif upper is None:
Expand Down Expand Up @@ -193,6 +194,8 @@ def cmp(left: int, right: int) -> int:
def lcp_array(s: typing.Union[str, typing.List[int]],
sa: typing.List[int]) -> typing.List[int]:
'''
Longest-Common-Prefix computation

Reference:
T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park,
Linear-Time Longest-Common-Prefix Computation in Suffix Arrays and Its
Expand Down Expand Up @@ -228,6 +231,8 @@ def lcp_array(s: typing.Union[str, typing.List[int]],

def z_algorithm(s: typing.Union[str, typing.List[int]]) -> typing.List[int]:
'''
Z algorithm

Reference:
D. Gusfield,
Algorithms on Strings, Trees, and Sequences: Computer Science and
Expand Down
2 changes: 2 additions & 0 deletions atcoder/twosat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class TwoSAT:
'''
2-SAT

Reference:
B. Aspvall, M. Plass, and R. Tarjan,
A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean
Expand Down