結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-10-14 00:41:51 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,732 ms / 2,000 ms | 
| コード長 | 646 bytes | 
| コンパイル時間 | 434 ms | 
| コンパイル使用メモリ | 12,160 KB | 
| 実行使用メモリ | 77,300 KB | 
| 最終ジャッジ日時 | 2025-10-14 00:42:10 | 
| 合計ジャッジ時間 | 19,748 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
from collections import deque
mod=10**9+7
s=list(map(lambda x:ord(x),list(input())))
x=[{} for i in range(11)]
for i in range(1,11):
	f=deque();c=0;d=10**i%mod;h=0;g=pow(31,i,mod)
	for j in range(len(s)):
		c*=10;c%=mod;h*=31;h%=mod
		if len(f)>=i:
			k=f.popleft()
			c+=mod-k*d%mod
			c%=mod
			h+=mod-k*g%mod
			h%=mod
		c+=s[j];c%=mod
		h+=s[j];h%=mod
		f.append(s[j])
		if (c,h) not in x[i]:
			x[i][(c,h)]=0
		x[i][(c,h)]+=1
m=int(input());ans=0
for i in range(m):
	s=list(input())
	c=0;h=0
	for j in s:
		c*=10;c+=ord(j)
		c%=mod
		h*=31;h+=ord(j)
		h%=mod
	c=(c,h)
	if c not in x[len(s)]:
		continue
	else:
		ans+=x[len(s)][c]
print(ans)
            
            
            
        