結果

問題 No.150 "良問"(良問とは言っていない
ユーザー MaxMellonMaxMellon
提出日時 2017-07-03 00:35:47
言語 Ruby
(3.2.2)
結果
AC  
実行時間 484 ms / 5,000 ms
コード長 1,125 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 24,624 KB
最終ジャッジ日時 2023-08-01 10:16:25
合計ジャッジ時間 4,551 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
17,868 KB
testcase_01 AC 79 ms
15,164 KB
testcase_02 AC 79 ms
15,032 KB
testcase_03 AC 79 ms
15,300 KB
testcase_04 AC 80 ms
15,312 KB
testcase_05 AC 84 ms
15,264 KB
testcase_06 AC 484 ms
24,624 KB
testcase_07 AC 78 ms
15,088 KB
testcase_08 AC 80 ms
15,072 KB
testcase_09 AC 82 ms
15,076 KB
testcase_10 AC 178 ms
17,840 KB
testcase_11 AC 191 ms
18,088 KB
testcase_12 AC 153 ms
17,128 KB
testcase_13 AC 186 ms
18,280 KB
testcase_14 AC 213 ms
19,136 KB
testcase_15 AC 207 ms
18,588 KB
testcase_16 AC 88 ms
15,228 KB
testcase_17 AC 118 ms
16,128 KB
testcase_18 AC 204 ms
19,372 KB
testcase_19 AC 229 ms
19,772 KB
testcase_20 AC 235 ms
19,916 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