結果

問題 No.430 文字列検索
ユーザー chomeyamachomeyama
提出日時 2019-08-10 02:54:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,090 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 10,724 KB
最終ジャッジ日時 2023-09-26 23:07:00
合計ジャッジ時間 2,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,904 KB
testcase_01 AC 288 ms
10,456 KB
testcase_02 AC 58 ms
10,384 KB
testcase_03 WA -
testcase_04 AC 31 ms
9,940 KB
testcase_05 AC 31 ms
9,940 KB
testcase_06 AC 32 ms
9,932 KB
testcase_07 AC 32 ms
9,892 KB
testcase_08 AC 53 ms
10,076 KB
testcase_09 AC 32 ms
9,904 KB
testcase_10 AC 37 ms
9,856 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction

CHRtoINT = defaultdict(int)
AtoZ = [chr(i) for i in range(65,65+26)]
for i, c in enumerate(AtoZ):
    CHRtoINT[c] = i

def RollingHash(S, s, x, b=26, m=2147483647):
    B, val, se = pow(b, x-1, m), 0, set()
    for _s in s:
        v, t = 0, B
        for c in _s:
            v = (v + CHRtoINT[c] * t) % m
            t //= b
        se.add(v)
    t = B
    for c in S[:x]:
        val = (val + CHRtoINT[c] * t) % m
        t //= b
    ret = int(val in se)
    B *= b
    for i, c in enumerate(S[:-x]):
        val = (val * b - CHRtoINT[c] * B + CHRtoINT[S[i+x]]) % m
        ret += int(val in se)
    return ret

S = input()
M = int(input())
s = [input() for i in range(M)]
s.sort(key=lambda x: len(x))
l, r, ans = 0, 0, 0
for k in range(len(s[0]), len(s[-1])+1):
    while r < M and len(s[r]) == k:
        r += 1
    if l != r:
        ans += RollingHash(S, s[l:r], k)
        l = r
print(ans)
0