結果

問題 No.430 文字列検索
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-01-18 17:31:22
言語 Ruby
(3.3.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 24,756 KB
最終ジャッジ日時 2023-09-02 11:49:32
合計ジャッジ時間 4,975 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,040 KB
testcase_01 AC 206 ms
24,756 KB
testcase_02 AC 287 ms
19,804 KB
testcase_03 AC 214 ms
19,700 KB
testcase_04 AC 86 ms
15,096 KB
testcase_05 AC 84 ms
15,240 KB
testcase_06 AC 84 ms
15,100 KB
testcase_07 AC 84 ms
15,148 KB
testcase_08 AC 123 ms
19,224 KB
testcase_09 AC 86 ms
15,096 KB
testcase_10 AC 92 ms
15,236 KB
testcase_11 AC 275 ms
21,728 KB
testcase_12 AC 284 ms
22,396 KB
testcase_13 AC 282 ms
22,488 KB
testcase_14 AC 227 ms
21,076 KB
testcase_15 AC 220 ms
20,524 KB
testcase_16 AC 281 ms
20,296 KB
testcase_17 AC 289 ms
20,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def fs(s1,p1,hs)
	res=0
	res+=hs["0"] if hs.member?("0")
	return res if s1.size<=p1
	e=s1[p1]
	if hs.member?(e) then
		res+=fs(s1,p1+1,hs[e])
	end
	return res
end
def f(s1,p1,hs)
	if s1.size<=p1 then
		hs["0"]=0 if hs.member?("0")==false
		hs["0"]+=1
	else
		e=s1[p1]
		if hs.member?(e) then
			f(s1,p1+1,hs[e])
		else
			hs[e]={}
			f(s1,p1+1,hs[e])
		end
	end
end
s=gets.chomp.split("")
hs={}
gets.to_i.times{
	s2=gets.chomp
	f(s2,0,hs)
}
ans=0
s.size.times{|p1|
	ans+=fs(s,p1,hs)
}
puts ans
0