結果

問題 No.1433 Two color sequence
ユーザー simansiman
提出日時 2021-03-21 04:10:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 452 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 33,024 KB
最終ジャッジ日時 2024-05-01 13:40:01
合計ジャッジ時間 10,176 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 86 ms
12,160 KB
testcase_02 AC 89 ms
12,160 KB
testcase_03 AC 431 ms
30,848 KB
testcase_04 AC 430 ms
30,848 KB
testcase_05 AC 87 ms
12,160 KB
testcase_06 AC 87 ms
12,160 KB
testcase_07 AC 85 ms
12,160 KB
testcase_08 AC 435 ms
32,128 KB
testcase_09 AC 435 ms
32,768 KB
testcase_10 AC 423 ms
32,512 KB
testcase_11 AC 428 ms
32,640 KB
testcase_12 AC 439 ms
32,768 KB
testcase_13 AC 430 ms
32,768 KB
testcase_14 AC 443 ms
32,000 KB
testcase_15 AC 452 ms
32,128 KB
testcase_16 AC 447 ms
33,024 KB
testcase_17 AC 442 ms
32,000 KB
testcase_18 AC 440 ms
32,128 KB
testcase_19 AC 449 ms
32,896 KB
testcase_20 AC 448 ms
32,896 KB
testcase_21 AC 441 ms
32,256 KB
testcase_22 AC 440 ms
32,128 KB
testcase_23 AC 443 ms
32,000 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - v
Syntax OK

ソースコード

diff #

N = gets.to_i
S = gets.chomp
A = gets.split.map(&:to_i)

cur = Array.new(2) { Array.new(2, 0) }
ans = -Float::INFINITY

A.zip(S.chars) do |a, s|
  2.times do |i|
    r, b = cur[i]
    v = (r - b).abs

    nr = (s == 'R') ? r + a : r
    nb = (s == 'B') ? b + a : b
    nv = (nr - nb).abs
    ans = nv if ans < nv

    if i == 0
      if nr >= nb
        cur[i] = [nr, nb]
      else
        cur[i] = [0, 0]
      end
    else
      if nr <= nb
        cur[i] = [nr, nb]
      else
        cur[i] = [0, 0]
      end
    end
  end
end

puts ans
0