結果

問題 No.430 文字列検索
ユーザー mattu34mattu34
提出日時 2023-04-11 14:13:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 537 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 137,072 KB
最終ジャッジ日時 2024-04-16 12:27:12
合計ジャッジ時間 5,669 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,632 KB
testcase_01 AC 537 ms
137,072 KB
testcase_02 AC 317 ms
77,184 KB
testcase_03 AC 323 ms
77,440 KB
testcase_04 AC 45 ms
53,376 KB
testcase_05 AC 46 ms
53,888 KB
testcase_06 AC 46 ms
53,504 KB
testcase_07 AC 46 ms
54,144 KB
testcase_08 AC 486 ms
136,568 KB
testcase_09 AC 55 ms
60,928 KB
testcase_10 AC 113 ms
79,744 KB
testcase_11 AC 381 ms
85,408 KB
testcase_12 AC 380 ms
85,424 KB
testcase_13 AC 376 ms
85,424 KB
testcase_14 AC 361 ms
82,760 KB
testcase_15 AC 347 ms
80,768 KB
testcase_16 AC 323 ms
77,312 KB
testcase_17 AC 315 ms
77,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

b=30
def str_to_num(s):
    res=[]
    for ss in s:
        res.append(ord(ss)-ord("A")+1)
    return res
def calc_h(s):
    L=str_to_num(s)
    h=0
    for i in range(len(L)):
        h+=L[i]*b**i
    return h
S=input()
d=defaultdict(int)
for i in range(1,11):
    for j in range(len(S)-i+1):
        d[calc_h(S[j:j+i])]+=1

ans=0
M=int(input())
for _ in range(M):
    ans+=d[calc_h(input())]
print(ans)
0