結果

問題 No.430 文字列検索
コンテスト
ユーザー lllllll88938494
提出日時 2023-05-20 14:26:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 612 ms / 2,000 ms
コード長 708 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 211 ms
コンパイル使用メモリ 85,528 KB
実行使用メモリ 251,352 KB
最終ジャッジ日時 2026-05-09 12:17:18
合計ジャッジ時間 6,774 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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