結果

問題 No.38 赤青白ブロック
ユーザー letrangerjpletrangerjp
提出日時 2017-06-14 11:16:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 263 ms / 5,000 ms
コード長 460 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 16,424 KB
最終ジャッジ日時 2023-08-25 01:22:43
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,272 KB
testcase_01 AC 203 ms
16,424 KB
testcase_02 AC 102 ms
15,600 KB
testcase_03 AC 87 ms
15,192 KB
testcase_04 AC 83 ms
15,244 KB
testcase_05 AC 79 ms
15,296 KB
testcase_06 AC 170 ms
16,384 KB
testcase_07 AC 113 ms
15,860 KB
testcase_08 AC 78 ms
15,060 KB
testcase_09 AC 177 ms
16,280 KB
testcase_10 AC 79 ms
15,288 KB
testcase_11 AC 79 ms
15,168 KB
testcase_12 AC 78 ms
15,080 KB
testcase_13 AC 79 ms
15,056 KB
testcase_14 AC 79 ms
15,268 KB
testcase_15 AC 101 ms
15,304 KB
testcase_16 AC 130 ms
15,708 KB
testcase_17 AC 91 ms
15,464 KB
testcase_18 AC 120 ms
15,584 KB
testcase_19 AC 101 ms
15,296 KB
testcase_20 AC 92 ms
15,160 KB
testcase_21 AC 88 ms
15,396 KB
testcase_22 AC 263 ms
16,356 KB
testcase_23 AC 79 ms
15,240 KB
testcase_24 AC 129 ms
15,952 KB
testcase_25 AC 86 ms
15,424 KB
testcase_26 AC 87 ms
15,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
  $memo[s] ||= if valid?(s) || n <= $ans
    $ans = [$ans, n].max
  else
    n.times.map{|i|
      next 0 if s[i] == ?W
      t = s[0...i] + s[i + 1..-1]
      f(t)
    }.max
  end
end

p f(S)
0