結果

問題 No.430 文字列検索
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-07 23:48:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-05-03 04:40:21
合計ジャッジ時間 2,181 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
52,480 KB
testcase_01 AC 110 ms
76,672 KB
testcase_02 AC 94 ms
76,672 KB
testcase_03 AC 96 ms
76,708 KB
testcase_04 AC 40 ms
51,968 KB
testcase_05 AC 37 ms
51,712 KB
testcase_06 AC 37 ms
52,224 KB
testcase_07 AC 37 ms
52,608 KB
testcase_08 AC 56 ms
73,344 KB
testcase_09 AC 44 ms
58,496 KB
testcase_10 AC 47 ms
61,824 KB
testcase_11 AC 83 ms
76,288 KB
testcase_12 AC 82 ms
76,800 KB
testcase_13 AC 81 ms
76,728 KB
testcase_14 AC 81 ms
76,784 KB
testcase_15 AC 83 ms
76,792 KB
testcase_16 AC 80 ms
76,416 KB
testcase_17 AC 82 ms
76,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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