結果

問題 No.150 "良問"(良問とは言っていない
ユーザー MaxMellonMaxMellon
提出日時 2017-07-03 00:49:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 546 ms / 5,000 ms
コード長 994 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-04-19 09:45:09
合計ジャッジ時間 4,745 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 191 ms
14,720 KB
testcase_01 AC 87 ms
12,160 KB
testcase_02 AC 87 ms
12,416 KB
testcase_03 AC 88 ms
12,416 KB
testcase_04 AC 87 ms
12,160 KB
testcase_05 AC 95 ms
12,544 KB
testcase_06 AC 546 ms
20,736 KB
testcase_07 AC 88 ms
12,288 KB
testcase_08 AC 92 ms
12,416 KB
testcase_09 AC 93 ms
12,416 KB
testcase_10 AC 201 ms
14,848 KB
testcase_11 AC 219 ms
15,232 KB
testcase_12 AC 172 ms
13,696 KB
testcase_13 AC 211 ms
15,104 KB
testcase_14 AC 245 ms
15,616 KB
testcase_15 AC 239 ms
15,360 KB
testcase_16 AC 103 ms
12,544 KB
testcase_17 AC 135 ms
13,312 KB
testcase_18 AC 241 ms
15,872 KB
testcase_19 AC 267 ms
16,640 KB
testcase_20 AC 272 ms
16,768 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
arr = []
(0...n).each do
  arr.push gets.chomp
end

class Symbol
  def call(*a,&b)
    proc {|m| m.send(self, *a, &b) }
  end
end

arr.map!(&:split.(''))

g_memo = {}
p_memo = {}

def create_memo_of_humming(str, line, start)
  r = []
  str.split('').each_with_index do |c, i|
    r.push line[start + i] == c
  end
  r
end

def create_memo(str, line)
  memo = {}
  line.each_with_index do |_, j|
    break if line.length - str.length < j
    r = create_memo_of_humming(str, line, j)
    memo[j] = { memo: r, start: j }
  end
  memo
end

arr.each_with_index do |line, i|
  g_memo[i] = {}
  p_memo[i] = {}
  g_memo[i] = create_memo('good', line)
  p_memo[i] = create_memo('problem', line)

  min = 0xFFFFFFF
  g_memo[i].each do |gkv|
    gc = 4 - gkv[1][:memo].count(true)
    ge = gkv[1][:start] + 3
    p_memo[i].each do |pkv|
      pc = 7 - pkv[1][:memo].count(true)
      pi = pkv[1][:start]
      min = gc + pc if (ge < pi) && (min > gc + pc)
    end
  end
  puts min
end
0