結果

問題 No.38 赤青白ブロック
ユーザー letrangerjpletrangerjp
提出日時 2017-06-14 09:27:38
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 799 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 11,992 KB
実行使用メモリ 20,880 KB
最終ジャッジ日時 2023-10-24 23:34:15
合計ジャッジ時間 12,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]
while !q.empty?
  s = q.shift
  S.size.times{|i|
    ngs = ng_at(s, i)
    ngs.each{|ng_idx|
      t = s[0...ng_idx] + s[ng_idx..-1]
      if valid?(t)
        p t
        exit
      end
      q << t if !q.include?(t)
    }
  }
end
0