結果

問題 No.430 文字列検索
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-07 23:46:25
言語 Python2
(2.7.18)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 6,708 KB
実行使用メモリ 6,424 KB
最終ジャッジ日時 2023-08-15 17:47:11
合計ジャッジ時間 1,620 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,928 KB
testcase_01 AC 75 ms
6,424 KB
testcase_02 AC 64 ms
6,300 KB
testcase_03 AC 63 ms
6,276 KB
testcase_04 AC 9 ms
5,948 KB
testcase_05 AC 9 ms
5,840 KB
testcase_06 AC 9 ms
6,108 KB
testcase_07 AC 9 ms
5,920 KB
testcase_08 AC 55 ms
6,168 KB
testcase_09 AC 10 ms
5,904 KB
testcase_10 AC 14 ms
5,880 KB
testcase_11 AC 66 ms
6,364 KB
testcase_12 AC 68 ms
6,368 KB
testcase_13 AC 64 ms
6,324 KB
testcase_14 AC 64 ms
6,232 KB
testcase_15 AC 65 ms
6,392 KB
testcase_16 AC 65 ms
6,332 KB
testcase_17 AC 65 ms
6,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

input = raw_input
range = xrange

def read_data():
    S = input()
    M = int(input())
    Cs = [input() for _ in range(M)]
    return S, M, Cs

def solve(S, M, Cs):
    base = ord('A') - 1
    mask10 = (1 << 50) - 1
    mask = init_mask(10)
    pool = init_pool(Cs)
    count = 0
    val = 0
    for c in S:
        val = ((val << 5) + ord(c) - base) & mask10
        for i in range(10):
            if (val & mask[i]) in pool[i]:
                count += 1
    return count

def init_mask(n):
    mask = []
    for i in range(1, n + 1):
        mask.append((1 << (5 * i)) - 1)
    return mask

def init_pool(Cs):
    base = ord('A') - 1
    pool = [set() for _ in range(10)]
    for C in Cs:
        val = 0
        for c in C:
            val = (val << 5) + ord(c) - base
        pool[len(C) - 1].add(val)
    return pool

S, M, Cs = read_data()
print(solve(S, M, Cs))
0