init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
30
5D.py
Normal file
30
5D.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import sys
|
||||
|
||||
line = sys.stdin.buffer.readline().split()
|
||||
n, m = int(line[0]), int(line[1])
|
||||
g = sys.stdin.buffer.readline().strip()
|
||||
pi = [0] * n
|
||||
for i in range(1, n):
|
||||
j = pi[i-1]
|
||||
while j > 0 and g[i] != g[j]:
|
||||
j = pi[j-1]
|
||||
if g[i] == g[j]: j += 1
|
||||
pi[i] = j
|
||||
ans = 0
|
||||
idx = 0
|
||||
j = 0
|
||||
while True:
|
||||
chunk = sys.stdin.buffer.read(131072)
|
||||
if not chunk:
|
||||
break
|
||||
chunk = chunk.replace(b'\n', b'').replace(b'\r', b'')
|
||||
for c in chunk:
|
||||
while j > 0 and c != g[j]:
|
||||
j = pi[j-1]
|
||||
if c == g[j]:
|
||||
j += 1
|
||||
if j == n:
|
||||
ans += (idx - n + 1)
|
||||
j = pi[n-1]
|
||||
idx += 1
|
||||
print(ans)
|
||||
Loading…
Add table
Add a link
Reference in a new issue