結果

問題 No.38 赤青白ブロック
ユーザー letrangerjpletrangerjp
提出日時 2017-06-14 09:35:43
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 843 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 11,984 KB
実行使用メモリ 16,340 KB
最終ジャッジ日時 2023-10-24 23:43:57
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
16,140 KB
testcase_01 AC 122 ms
16,256 KB
testcase_02 AC 84 ms
16,140 KB
testcase_03 AC 84 ms
16,140 KB
testcase_04 AC 85 ms
16,140 KB
testcase_05 AC 84 ms
16,140 KB
testcase_06 AC 88 ms
16,140 KB
testcase_07 AC 86 ms
16,140 KB
testcase_08 AC 84 ms
16,140 KB
testcase_09 AC 90 ms
16,256 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 84 ms
16,140 KB
testcase_16 AC 88 ms
16,256 KB
testcase_17 AC 85 ms
16,136 KB
testcase_18 AC 85 ms
16,136 KB
testcase_19 AC 87 ms
16,140 KB
testcase_20 AC 87 ms
16,140 KB
testcase_21 AC 86 ms
16,140 KB
testcase_22 AC 93 ms
16,256 KB
testcase_23 AC 84 ms
16,140 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 85 ms
16,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

Kr, Kb = gets.split.take(2).map(&:to_i)
S = gets.chomp

def ng_at(s, i)
  r = []
  range = 0...s.size
  !case s[i]
  when ?R
    r << i - Kr if range.cover?(i - Kr) && s[i - Kr] == ?R
    r << i + Kr if range.cover?(i + Kr) && s[i + Kr] == ?R
  when ?B
    r << i - Kb if range.cover?(i - Kb) && s[i - Kb] == ?B
    r << i + Kb if range.cover?(i + Kb) && s[i + Kb] == ?B
  else
  end
  r
end

def valid?(s)
  !s.size.times.any?{|i|
    !ng_at(s, i).empty?
  }
end

def count_ng(s)
  count = 0
  s.size.times{|i|
    count += ng_at(s, i).size
  }
  count
end

q = {S=>1}
while !q.empty?
  qq = {}
  q.keys.each{|s|
    s.size.times{|i|
      ngs = ng_at(s, i)
      ngs.each{|ng_idx|
        t = s[0...ng_idx] + s[ng_idx+1..-1]
        if valid?(t)
          p t.size
          exit
        end
        qq[t] = 1
      }
    }
  }
  q = qq
end
0