結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-08 03:35:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 356 ms / 2,000 ms |
| コード長 | 1,432 bytes |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 93,184 KB |
| 最終ジャッジ日時 | 2024-11-10 00:59:36 |
| 合計ジャッジ時間 | 4,919 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
from collections import defaultdict
import math
import sys
import os
from typing import *
sys.setrecursionlimit(100000)
is_local = "TERM_PROGRAM" in os.environ
input = sys.stdin.readline
INF = float('inf')
def debug(*args, **kwargs):
if is_local:
print(*args, **kwargs)
def I(): return input().rstrip()
def IS(): return input().split()
def II(): return int(input())
def IIS(): return map(int, input().split())
def LIIS(): return list(map(int, input().split()))
MOD = 2**61 - 1
def main():
s = I()
n = len(s)
hashes = [[] for _ in range(10)]
hashes[0].append(ord(s[0]) - ord("A"))
pows = [1]
for _ in range(10):
pows.append((pows[-1]*26) % MOD)
for i in range(10):
if i >= n:
break
if i > 0:
hashes[i].append((hashes[i-1][0]*26 + ord(s[i]) - ord("A")) % MOD)
for j in range(n - i - 1):
x = hashes[i][-1]
x -= (ord(s[j]) - ord("A")) * pows[i]
x %= MOD
x = (x * 26) % MOD
x += (ord(s[j+i+1]) - ord("A"))
x %= MOD
hashes[i].append(x)
m = II()
out = 0
for _ in range(m):
ss = I()
l = len(ss)
h = 0
for i in range(l):
h *= 26
h %= MOD
h += ord(ss[i]) - ord("A")
h %= MOD
out += hashes[l-1].count(h)
print(out)
if __name__ == "__main__":
main()