結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2016-10-03 00:14:50 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 302 ms / 2,000 ms |
| コード長 | 806 bytes |
| コンパイル時間 | 39 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2024-11-10 00:06:23 |
| 合計ジャッジ時間 | 3,979 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
コンパイルメッセージ
Syntax OK
ソースコード
class Trie
class Node
def initialize()
@value = 0
@child = {}
end
attr_accessor :value, :child
end
def initialize()
@root = Node.new
end
def insert(str)
now = @root
str.each_char do |c|
if now.child[c] == nil
now.child[c] = Node.new
end
now = now.child[c]
end
now.value = now.value+1
end
attr_accessor :root
end
S = gets
M = gets.to_i
C = $stdin.read.split(?\n)
trie = Trie.new
for c in C do
trie.insert(c)
end
N = S.length
ans = 0
for i in 0..N-1 do
now = trie.root
for j in 0..10 do
break if now == nil
now = now.child[S[i+j]]
if now != nil
ans += now.value
end
end
end
p ans
mayoko_