結果

問題 No.430 文字列検索
ユーザー nebukuro09nebukuro09
提出日時 2016-10-03 11:03:35
言語 Python2
(2.7.18)
結果
AC  
実行時間 617 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 51,808 KB
最終ジャッジ日時 2024-05-03 04:29:42
合計ジャッジ時間 7,388 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,400 KB
testcase_01 AC 617 ms
51,808 KB
testcase_02 AC 513 ms
6,912 KB
testcase_03 AC 519 ms
6,784 KB
testcase_04 AC 12 ms
6,400 KB
testcase_05 AC 11 ms
6,400 KB
testcase_06 AC 10 ms
6,400 KB
testcase_07 AC 11 ms
6,400 KB
testcase_08 AC 588 ms
51,628 KB
testcase_09 AC 12 ms
6,272 KB
testcase_10 AC 60 ms
10,752 KB
testcase_11 AC 519 ms
11,296 KB
testcase_12 AC 520 ms
11,420 KB
testcase_13 AC 521 ms
11,420 KB
testcase_14 AC 518 ms
11,136 KB
testcase_15 AC 517 ms
8,064 KB
testcase_16 AC 524 ms
6,784 KB
testcase_17 AC 512 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = raw_input()
M = input()
C = [raw_input() for _ in xrange(M)]
Ch = []
for s in C:
    h = 0
    for i, c in enumerate(s):
        h += 26**i*(ord(c)-ord('A')+1)
    Ch.append(h)

N = len(S)
rolling_hash = {}
for n in xrange(1, 11):
    if n > N:
        break
    h = 0
    for i in xrange(n):
        h += 26**i*(ord(S[i])-ord('A')+1)
    if h in rolling_hash:
        rolling_hash[h] += 1
    else:
        rolling_hash[h] = 1
    for i in xrange(n, N):
        h -= ord(S[i-n])-ord('A')+1
        h /= 26
        h += 26**(n-1)*(ord(S[i])-ord('A')+1) 
        if h in rolling_hash:
            rolling_hash[h] += 1
        else:
            rolling_hash[h] = 1

ans = 0            
for c in Ch:
    if c in rolling_hash:
        ans += rolling_hash[c]
print ans
0