competitive-programming-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub yu-0811/competitive-programming-library

:warning: algorithm_library/python/string/Z-algo.py

Code

# Z[i] := S[0:|S|) と S[i:|S|) の最長共通接頭辞の長さ
def z_algo(S):
  Z = [0]*len(S)
  Z[0] = len(S)
  i,j = 1,0
  while i<len(S):
    # 一致する限り延長する
    while (i+j<len(S) and S[j]==S[i+j]): j += 1
    Z[i] = j
    
    # 一文字も一致しないならコピーできないので次に進む
    if j==0: 
      i += 1
      continue
    
    k = 1
    # k+Z[k]>j なら1回目の登場の際にはみ出してしまっている
    # k+Z[k]=j なら2回目の登場の際にはみ出す可能性がある
    while (k<j and k+Z[k]<j):
      Z[i+k] = Z[k]
      k += 1
    # まだ未確定なところまで i を進める
    i += k
    # j を i に合わせる
    j -= k
    
  return Z
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.0/x64/lib/python3.11/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.11.0/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page