結果

問題 No.430 文字列検索
ユーザー takakintakakin
提出日時 2020-04-24 00:41:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 526 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 52,608 KB
最終ジャッジ日時 2024-04-22 08:57:44
合計ジャッジ時間 10,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 912 ms
52,492 KB
testcase_02 AC 722 ms
11,136 KB
testcase_03 AC 721 ms
11,136 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 30 ms
10,624 KB
testcase_08 AC 959 ms
52,608 KB
testcase_09 RE -
testcase_10 AC 107 ms
13,264 KB
testcase_11 AC 759 ms
16,144 KB
testcase_12 AC 764 ms
16,080 KB
testcase_13 AC 761 ms
16,076 KB
testcase_14 AC 734 ms
13,516 KB
testcase_15 AC 741 ms
13,364 KB
testcase_16 AC 730 ms
11,776 KB
testcase_17 AC 731 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
S=input()
n=len(S)
m=int(input())
import collections
RH=collections.defaultdict(int)
base=37;mod=10**9+7

for l in range(10):
  v=0
  for i in range(l+1):
    v=((v+ord(S[i]))*base)%mod
  RH[v]+=1
  for i in range(l+1,n):
    v=(((v-ord(S[i-l-1])*pow(base,l+1,mod))+ord(S[i]))*base)%mod
    RH[v]+=1
ans=0
for _ in range(m):
  C=input()
  lc=len(C)
  if lc>n:
    continue
  else:
    v=0
    for i in range(lc):
      v=((v+ord(C[i]))*base)%mod
    ans+=RH[v]
print(ans)
0