結果
問題 | No.430 文字列検索 |
ユーザー | marroncastle |
提出日時 | 2022-02-06 16:48:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 934 bytes |
コンパイル時間 | 378 ms |
コンパイル使用メモリ | 87,136 KB |
実行使用メモリ | 114,016 KB |
最終ジャッジ日時 | 2023-09-02 07:00:56 |
合計ジャッジ時間 | 5,356 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 104 ms
71,680 KB |
testcase_01 | AC | 420 ms
114,016 KB |
testcase_02 | AC | 263 ms
80,056 KB |
testcase_03 | AC | 241 ms
79,544 KB |
testcase_04 | AC | 103 ms
71,800 KB |
testcase_05 | AC | 104 ms
71,512 KB |
testcase_06 | AC | 102 ms
71,672 KB |
testcase_07 | AC | 103 ms
71,516 KB |
testcase_08 | AC | 354 ms
113,432 KB |
testcase_09 | AC | 114 ms
76,356 KB |
testcase_10 | AC | 140 ms
81,296 KB |
testcase_11 | AC | 276 ms
85,776 KB |
testcase_12 | AC | 284 ms
86,612 KB |
testcase_13 | AC | 279 ms
85,700 KB |
testcase_14 | AC | 265 ms
83,396 KB |
testcase_15 | AC | 257 ms
82,020 KB |
testcase_16 | AC | 235 ms
79,184 KB |
testcase_17 | AC | 246 ms
80,908 KB |
ソースコード
# 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 = 37; 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 ans = 0 for i in range(M): ans += dic[RollingHash(input(),base,mod).all()] print(ans)