結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2019-12-16 16:57:06 |
| 言語 | Ruby (4.0.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 631 bytes |
| 記録 | |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 36,132 KB |
| 最終ジャッジ日時 | 2024-11-10 00:39:45 |
| 合計ジャッジ時間 | 4,127 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 1 TLE * 1 -- * 12 |
コンパイルメッセージ
Syntax OK
ソースコード
class String
def contain_points(str)
l1 = size
l2 = str.size
return [] if l1 < l2
base = 10 ** 9 + 7
t = 1
l2.times { t *= base }
cp = codepoints
h1 = 0
h2 = 0
l2.times do |i|
h1 = h1 * base + cp[i]
h2 = h2 * base + str[i].ord
end
i = 0
result = []
while i + l2 <= l1
result << i if h1 == h2
if i + l2 < l1
h1 = h1 * base + cp[i + l2] - cp[i] * t
end
i += 1
end
result
end
end
S = gets.chomp
M = gets.to_i
ans = 0
M.times do
str = gets.chomp
res = S.contain_points(str)
ans += res.size
end
puts ans
siman