結果

問題 No.430 文字列検索
ユーザー lllllll88938494
提出日時 2023-05-20 14:26:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 246,572 KB
最終ジャッジ日時 2024-11-10 01:06:32
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict as df 
class trie:
    def  __init__(self):
        self.exist = 0
        self.kodomo = df(trie)
        
    def  add(self,moji):
        now = ne
        for i in moji:
            now = now.kodomo[i]
        now.exist += 1
        
    def  find(self,moji):
        now = ne
        for i in moji:
            if not now.kodomo[i]:
                return False
            now = now.kodomo[i]
        return now.exist
        

s=input()
ne = trie()

for i in range(len(s)):
    t=''
    for j in range(i,min(i+10,len(s))):
        t+=s[j]
        ne.add(t)
    
    
q=int(input())
ans = 0
for i in range(q):
    t = input()
    ans += ne.find(t)
        
print(ans)
0