結果

問題 No.430 文字列検索
ユーザー s_shoheis_shohei
提出日時 2020-04-23 17:46:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 722 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 137,472 KB
最終ジャッジ日時 2024-04-21 19:05:03
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,504 KB
testcase_01 AC 201 ms
137,472 KB
testcase_02 AC 111 ms
78,208 KB
testcase_03 AC 109 ms
78,080 KB
testcase_04 AC 43 ms
53,760 KB
testcase_05 AC 43 ms
53,888 KB
testcase_06 AC 44 ms
53,760 KB
testcase_07 AC 42 ms
53,888 KB
testcase_08 AC 157 ms
133,888 KB
testcase_09 AC 54 ms
61,440 KB
testcase_10 AC 72 ms
72,448 KB
testcase_11 AC 135 ms
86,912 KB
testcase_12 AC 130 ms
87,040 KB
testcase_13 AC 129 ms
87,168 KB
testcase_14 AC 124 ms
82,432 KB
testcase_15 AC 120 ms
80,384 KB
testcase_16 AC 110 ms
78,208 KB
testcase_17 AC 117 ms
78,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s=input()
m=int(input())
c=[input() for i in range(m)]

class RHash():
    def __init__(self, s, base=37, mod=10**9+9):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)

        l = len(s)
        self.h = h = [0]*(l+1)

        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod

rh = RHash(s)
from collections import defaultdict
d = defaultdict(int)
for l in range(1,11):
    for i in range(len(s)-l+1):
        hsh = rh.get(i,i+l)
        d[hsh] += 1

ans=0
for st in c:
    hsh = RHash(st).get(0,len(st))
    ans+=d[hsh]
print(ans)
0