結果

問題 No.430 文字列検索
ユーザー ayaoniayaoni
提出日時 2021-05-03 23:17:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 988 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 82,508 KB
最終ジャッジ日時 2023-09-29 19:22:18
合計ジャッジ時間 16,947 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,164 KB
testcase_01 AC 1,544 ms
82,176 KB
testcase_02 AC 1,510 ms
81,808 KB
testcase_03 AC 1,415 ms
82,440 KB
testcase_04 AC 69 ms
71,220 KB
testcase_05 AC 68 ms
71,384 KB
testcase_06 AC 68 ms
71,360 KB
testcase_07 AC 67 ms
71,276 KB
testcase_08 AC 92 ms
81,244 KB
testcase_09 RE -
testcase_10 AC 84 ms
76,184 KB
testcase_11 AC 1,438 ms
82,380 KB
testcase_12 AC 1,529 ms
82,360 KB
testcase_13 AC 1,527 ms
82,496 KB
testcase_14 AC 1,532 ms
82,496 KB
testcase_15 AC 1,507 ms
82,360 KB
testcase_16 AC 1,522 ms
82,508 KB
testcase_17 AC 1,529 ms
82,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


T = S()
N = len(T)

base = 1234
mod = 10**9+7
AH = [0]
for t in T:
    AH.append((AH[-1]*base+ord(t)) % mod)

base_power = [1]
for _ in range(N):
    base_power.append((base_power[-1]*base) % mod)


def RH(i,j):  # (i,j]
    return (AH[j]-AH[i]*base_power[j-i]) % mod


M = I()
ans = 0
for _ in range(M):
    C = S()
    len_C = len(C)

    rh = 0
    for i in range(len_C):
        rh += ord(C[i])*base_power[len_C-1-i]
        rh %= mod

    for i in range(N-len_C+1):
        if rh == RH(i,i+len_C):
            ans += 1

print(ans)
0