結果
問題 | No.430 文字列検索 |
ユーザー | ayaoni |
提出日時 | 2021-05-03 23:25:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,609 ms / 2,000 ms |
コード長 | 1,023 bytes |
コンパイル時間 | 347 ms |
コンパイル使用メモリ | 86,840 KB |
実行使用メモリ | 82,468 KB |
最終ジャッジ日時 | 2023-09-29 19:29:20 |
合計ジャッジ時間 | 17,870 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
71,528 KB |
testcase_01 | AC | 1,606 ms
82,008 KB |
testcase_02 | AC | 1,597 ms
81,724 KB |
testcase_03 | AC | 1,505 ms
82,324 KB |
testcase_04 | AC | 71 ms
71,308 KB |
testcase_05 | AC | 72 ms
71,376 KB |
testcase_06 | AC | 71 ms
71,120 KB |
testcase_07 | AC | 69 ms
71,376 KB |
testcase_08 | AC | 92 ms
81,192 KB |
testcase_09 | AC | 73 ms
71,256 KB |
testcase_10 | AC | 85 ms
76,192 KB |
testcase_11 | AC | 1,510 ms
82,348 KB |
testcase_12 | AC | 1,603 ms
82,276 KB |
testcase_13 | AC | 1,605 ms
82,176 KB |
testcase_14 | AC | 1,604 ms
82,468 KB |
testcase_15 | AC | 1,602 ms
82,360 KB |
testcase_16 | AC | 1,602 ms
82,048 KB |
testcase_17 | AC | 1,609 ms
82,468 KB |
ソースコード
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) if len_C > N: continue 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)