結果

問題 No.430 文字列検索
ユーザー mayoko_mayoko_
提出日時 2016-10-03 00:14:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 11,300 KB
実行使用メモリ 21,076 KB
最終ジャッジ日時 2023-08-27 02:08:08
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,008 KB
testcase_01 AC 191 ms
21,076 KB
testcase_02 AC 282 ms
16,176 KB
testcase_03 AC 217 ms
15,952 KB
testcase_04 AC 77 ms
15,036 KB
testcase_05 AC 76 ms
15,300 KB
testcase_06 AC 74 ms
15,036 KB
testcase_07 AC 74 ms
15,176 KB
testcase_08 AC 120 ms
15,196 KB
testcase_09 AC 77 ms
15,232 KB
testcase_10 AC 81 ms
15,376 KB
testcase_11 AC 274 ms
18,764 KB
testcase_12 AC 280 ms
19,176 KB
testcase_13 AC 272 ms
19,132 KB
testcase_14 AC 228 ms
17,908 KB
testcase_15 AC 217 ms
16,364 KB
testcase_16 AC 278 ms
16,496 KB
testcase_17 AC 285 ms
16,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0