結果

問題 No.1374 Absolute Game
ユーザー maguroflymagurofly
提出日時 2021-02-05 22:16:33
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 421 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 11,332 KB
実行使用メモリ 813,556 KB
最終ジャッジ日時 2023-09-15 08:31:54
合計ジャッジ時間 6,370 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,108 KB
testcase_01 AC 80 ms
15,180 KB
testcase_02 AC 78 ms
15,276 KB
testcase_03 AC 79 ms
15,292 KB
testcase_04 AC 82 ms
15,040 KB
testcase_05 AC 80 ms
15,140 KB
testcase_06 AC 80 ms
15,280 KB
testcase_07 WA -
testcase_08 MLE -
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 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
c = gets.split.map(&:to_i).sort

dp = Array.new(N+1) { |l| x = []; x[l] = [0, 0]; x }
(1 .. N).each do |s|
    (0 .. N-s).each do |l|
        r = l + s
        b1, a1 = dp[l][r-1]
        b2, a2 = dp[l+1][r]
        a1 += c[r-1]
        a2 += c[l]
        dp[l][r] = [
            [a1, b1],
            [a2, b2],
            ].max_by { |(a, b)| a.abs - b.abs }
    end
end
a, b = dp[0][N]
puts a.abs - b.abs
0