結果

問題 No.430 文字列検索
ユーザー 前田悠真
提出日時 2025-08-09 10:14:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,752 KB
実行使用メモリ 80,568 KB
最終ジャッジ日時 2025-08-09 10:14:31
合計ジャッジ時間 2,764 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(map(lambda x:ord(x), input()))
n = int(input())
A = [list(map(lambda x:ord(x), input())) for _ in range(n)]

G = [{}]
size = 1
P = [0]

for A_ in A:
  now = 0
  for a in A_:
    if a in G[now]:
      now = G[now][a]
    else:
      G[now][a] = size
      G.append({})
      now = size
      size += 1
      P.append(0)
  P[now] += 1

m = len(S)
ans = 0
for i in range(m):
  now = 0
  for j in range(i, min(i+10, m)):
    if S[j] in G[now]:
      now = G[now][S[j]]
      ans += P[now]
    else:
      break
print(ans )
    

0