結果

問題 No.430 文字列検索
ユーザー lllllll88938494lllllll88938494
提出日時 2023-05-20 14:26:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 690 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 248,988 KB
最終ジャッジ日時 2023-08-23 09:35:59
合計ジャッジ時間 7,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,476 KB
testcase_01 AC 690 ms
248,988 KB
testcase_02 AC 282 ms
78,692 KB
testcase_03 AC 282 ms
78,124 KB
testcase_04 AC 97 ms
71,616 KB
testcase_05 AC 94 ms
71,460 KB
testcase_06 AC 97 ms
71,704 KB
testcase_07 AC 98 ms
71,464 KB
testcase_08 AC 642 ms
244,340 KB
testcase_09 AC 105 ms
77,404 KB
testcase_10 AC 161 ms
94,432 KB
testcase_11 AC 459 ms
99,276 KB
testcase_12 AC 469 ms
99,616 KB
testcase_13 AC 469 ms
99,632 KB
testcase_14 AC 413 ms
92,180 KB
testcase_15 AC 365 ms
86,492 KB
testcase_16 AC 312 ms
81,108 KB
testcase_17 AC 311 ms
80,436 KB
権限があれば一括ダウンロードができます

ソースコード

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