結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
s_shohei
|
| 提出日時 | 2020-04-23 17:41:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 761 bytes |
| コンパイル時間 | 155 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 565,524 KB |
| 最終ジャッジ日時 | 2024-11-10 00:43:26 |
| 合計ジャッジ時間 | 3,615 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 1 MLE * 1 -- * 12 |
ソースコード
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,len(s)+1):
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)
s_shohei