結果

問題 No.430 文字列検索
ユーザー marroncastlemarroncastle
提出日時 2022-02-06 16:53:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 101,676 KB
最終ジャッジ日時 2023-09-02 07:01:07
合計ジャッジ時間 4,849 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,716 KB
testcase_01 WA -
testcase_02 AC 207 ms
79,940 KB
testcase_03 AC 210 ms
79,924 KB
testcase_04 AC 92 ms
71,696 KB
testcase_05 AC 93 ms
71,440 KB
testcase_06 AC 91 ms
71,512 KB
testcase_07 AC 92 ms
71,912 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 245 ms
86,536 KB
testcase_12 AC 251 ms
86,580 KB
testcase_13 AC 244 ms
86,908 KB
testcase_14 AC 240 ms
83,056 KB
testcase_15 AC 226 ms
82,212 KB
testcase_16 AC 213 ms
79,408 KB
testcase_17 AC 211 ms
79,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 1-dimension Rolling Hash
# 参考 https://tjkendev.github.io/procon-library/python/string/rolling_hash.html

class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
        self.length = 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
    
    def all(self):
        return self.get(0, self.length)

base = 4; mod = 1<<61-1
S = input()
N = len(S)
M = int(input())
RHS = RollingHash(S,base,mod)
from collections import defaultdict
dic = defaultdict(lambda: 0)
for l in range(1,11):
    for i in range(N-l+1):dic[RHS.get(i,i+l)]+=1
print(sum(dic[RollingHash(input(),base,mod).all()]for _ in range(M)))
0