結果
問題 |
No.430 文字列検索
|
ユーザー |
![]() |
提出日時 | 2020-04-23 01:20:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 873 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-11-10 00:43:20 |
合計ジャッジ時間 | 1,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 4 |
other | RE * 14 |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) def SI(): return sys.stdin.readline()[:-1] def main(): def hash(aa): res = 0 base=1 for a in aa[::-1]: res += a*base base*=26 return res s=SI() s=[ord(c)-65 for c in s] sn=len(s) memo=[[-1]*sn for _ in range(11)] ans=0 for _ in range(II()): t=SI() t = [ord(c) - 65 for c in t] tn=len(t) ht=hash(t) memotn = memo[tn] if memotn[0]!=-1: memotn=memo[tn] for i in range(sn - tn + 1): if memotn[i]==ht:ans+=1 else: hs=hash(s[:tn]) mxd=pow(26,tn-1) for i in range(sn - tn + 1): if i:hs=(hs-mxd*s[i-1])*26+s[i+tn-1] if hs==ht:ans+=1 memotn[i]=hs print(ans) main()