結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2016-03-23 18:27:38 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 345 ms / 5,000 ms |
| コード長 | 905 bytes |
| コンパイル時間 | 246 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 13,348 KB |
| 最終ジャッジ日時 | 2024-10-11 02:00:59 |
| 合計ジャッジ時間 | 4,407 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
コンパイルメッセージ
Syntax OK
ソースコード
class Yukicoder
def initialize
t = gets.to_i
@cache_good = Hash.new
@cache_problem = Hash.new
t.times do
s = gets.chomp
size = s.size
min_dist = Float::INFINITY
0.upto(size - 7) do |i|
dist1 = calc_dist_good(s[i..i+3])
(i+4).upto(size - 7) do |j|
dist2 = calc_dist_problem(s[j..j+6])
min_dist = [min_dist, dist1 + dist2].min
end
end
puts min_dist
end
end
def calc_dist_good(str)
return @cache_good[str] if @cache_good[str]
dist = 0
0.upto(3) do |index|
dist += 1 if str[index] != 'good'[index]
end
@cache_good[str] = dist
end
def calc_dist_problem(str)
return @cache_problem[str] if @cache_problem[str]
dist = 0
0.upto(6) do |index|
dist += 1 if str[index] != 'problem'[index]
end
@cache_problem[str] = dist
end
end
Yukicoder.new
siman