Typical DP Contest

Submission #5889416

Source codeソースコード

gets
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

res = Array.new(as.size+1){Array.new(bs.size+1, 0)}

(0..as.size).reverse_each do |a|
  (0..bs.size).reverse_each do |b|
    next if a == as.size && b == bs.size
    if (a+b)%2 == 0
      if a == as.size
        res[a][b] = res[a][b+1] + bs[b]
      elsif b == bs.size
        res[a][b] = res[a+1][b] + as[a]
      else
        res[a][b] = [res[a+1][b] + as[a], res[a][b+1] + bs[b]].max
      end
    else
      if a == as.size
        res[a][b] = res[a][b+1]
      elsif b == bs.size
        res[a][b] = res[a+1][b]
      else
        res[a][b] = [res[a+1][b], res[a][b+1]].min
      end
    end
  end
end

p res[0][0]

Submission

Task問題 B - ゲーム
User nameユーザ名 somurie06
Created time投稿日時
Language言語 Ruby (2.3.3)
Status状態 AC
Score得点 3
Source lengthソースコード長 712 Byte
File nameファイル名
Exec time実行時間 734 ms
Memory usageメモリ使用量 9980 KB

Test case

Set

Set name Score得点 / Max score Cases
All 3 / 3 00,01,02,90,91

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00 AC 7 ms 1788 KB
01 AC 497 ms 7548 KB
02 AC 734 ms 9980 KB
90 AC 7 ms 1788 KB
91 AC 7 ms 1788 KB