結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 450 ms
16,196 KB
testcase_01 TLE -
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 valid?(s)
  !s.size.times.any?{|i|
    case s[i]
    when ?R
      i - Kr >= 0 && s[i - Kr] == ?R
    when ?B
      i - Kb >= 0 && s[i - Kb] == ?B
    end
  }
end

$memo = {}
$ans = 12
def f(s)
  n = s.size
  if valid?(s) || n <= $ans
    $ans = [$ans, n].max
  else
    n.times.map{|i|
      t = s[0...i] + s[i + 1..-1]
      f(t)
    }.max
  end
end

p f(S)
0