結果

問題 No.150 "良問"(良問とは言っていない
ユーザー MaxMellonMaxMellon
提出日時 2017-07-03 00:35:47
言語 Ruby
(3.3.0)
結果
AC  
実行時間 506 ms / 5,000 ms
コード長 1,125 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-04-19 09:47:02
合計ジャッジ時間 4,504 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
14,848 KB
testcase_01 AC 86 ms
12,416 KB
testcase_02 AC 86 ms
12,416 KB
testcase_03 AC 86 ms
12,160 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 93 ms
12,544 KB
testcase_06 AC 506 ms
20,224 KB
testcase_07 AC 85 ms
12,160 KB
testcase_08 AC 90 ms
12,160 KB
testcase_09 AC 90 ms
12,160 KB
testcase_10 AC 190 ms
14,848 KB
testcase_11 AC 205 ms
15,104 KB
testcase_12 AC 162 ms
13,824 KB
testcase_13 AC 199 ms
15,104 KB
testcase_14 AC 229 ms
15,488 KB
testcase_15 AC 219 ms
15,488 KB
testcase_16 AC 97 ms
12,544 KB
testcase_17 AC 126 ms
13,312 KB
testcase_18 AC 219 ms
15,744 KB
testcase_19 AC 247 ms
16,512 KB
testcase_20 AC 254 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 = {}
arr.each_with_index do |line, i|
  g_memo[i] = {}
  p_memo[i] = {}

  line.each_with_index do |c, j|
    break if line.length - 4 < j
    r = []
    r.push line[j  ] == 'g'
    r.push line[j+1] == 'o'
    r.push line[j+2] == 'o'
    r.push line[j+3] == 'd'
    g_memo[i][j] = {memo: r, start: j}
  end

  line.each_with_index do |c, j|
    break if line.length - 7 < j
    r = []
    r.push line[j  ] == 'p'
    r.push line[j+1] == 'r'
    r.push line[j+2] == 'o'
    r.push line[j+3] == 'b'
    r.push line[j+4] == 'l'
    r.push line[j+5] == 'e'
    r.push line[j+6] == 'm'
    p_memo[i][j] = {memo: r, start: j}
  end

  min = 99999999
  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]
      if (ge < pi) && (min > gc + pc)
        min = gc + pc
      end
    end
  end
  puts min
end
0