結果

問題 No.430 文字列検索
ユーザー rpy3cpprpy3cpp
提出日時 2016-10-07 23:36:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 9,508 KB
最終ジャッジ日時 2023-08-15 17:47:13
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,844 KB
testcase_01 AC 87 ms
9,180 KB
testcase_02 AC 82 ms
9,444 KB
testcase_03 AC 81 ms
9,508 KB
testcase_04 AC 13 ms
7,792 KB
testcase_05 AC 14 ms
7,832 KB
testcase_06 AC 13 ms
7,788 KB
testcase_07 AC 14 ms
7,800 KB
testcase_08 AC 72 ms
8,332 KB
testcase_09 AC 15 ms
7,792 KB
testcase_10 AC 18 ms
7,800 KB
testcase_11 AC 91 ms
9,120 KB
testcase_12 AC 86 ms
9,496 KB
testcase_13 AC 86 ms
9,440 KB
testcase_14 AC 85 ms
9,404 KB
testcase_15 AC 85 ms
9,400 KB
testcase_16 AC 86 ms
9,456 KB
testcase_17 AC 90 ms
9,444 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