結果

問題 No.150 "良問"(良問とは言っていない
ユーザー simansiman
提出日時 2016-03-23 18:27:38
言語 Ruby
(3.2.2)
結果
AC  
実行時間 315 ms / 5,000 ms
コード長 905 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 16,680 KB
最終ジャッジ日時 2023-08-01 10:00:25
合計ジャッジ時間 4,009 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
15,864 KB
testcase_01 AC 79 ms
15,172 KB
testcase_02 AC 80 ms
15,260 KB
testcase_03 AC 80 ms
15,184 KB
testcase_04 AC 80 ms
15,268 KB
testcase_05 AC 84 ms
15,292 KB
testcase_06 AC 315 ms
15,252 KB
testcase_07 AC 80 ms
15,308 KB
testcase_08 AC 83 ms
15,068 KB
testcase_09 AC 82 ms
15,152 KB
testcase_10 AC 153 ms
15,780 KB
testcase_11 AC 165 ms
15,948 KB
testcase_12 AC 135 ms
15,584 KB
testcase_13 AC 163 ms
15,944 KB
testcase_14 AC 185 ms
16,028 KB
testcase_15 AC 178 ms
16,004 KB
testcase_16 AC 88 ms
15,276 KB
testcase_17 AC 110 ms
15,340 KB
testcase_18 AC 178 ms
16,532 KB
testcase_19 AC 198 ms
16,516 KB
testcase_20 AC 201 ms
16,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0