結果

問題 No.1199 お菓子配り-2
ユーザー 小野寺健小野寺健
提出日時 2021-11-02 12:40:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 701 ms / 1,000 ms
コード長 317 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 21,248 KB
最終ジャッジ日時 2024-04-19 19:11:29
合計ジャッジ時間 27,238 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
12,160 KB
testcase_01 AC 81 ms
12,160 KB
testcase_02 AC 82 ms
12,032 KB
testcase_03 AC 257 ms
15,232 KB
testcase_04 AC 532 ms
19,584 KB
testcase_05 AC 93 ms
12,288 KB
testcase_06 AC 97 ms
12,544 KB
testcase_07 AC 230 ms
13,952 KB
testcase_08 AC 275 ms
14,336 KB
testcase_09 AC 191 ms
13,696 KB
testcase_10 AC 112 ms
12,544 KB
testcase_11 AC 169 ms
13,184 KB
testcase_12 AC 154 ms
12,800 KB
testcase_13 AC 104 ms
12,416 KB
testcase_14 AC 114 ms
12,672 KB
testcase_15 AC 105 ms
12,544 KB
testcase_16 AC 260 ms
14,080 KB
testcase_17 AC 217 ms
14,464 KB
testcase_18 AC 478 ms
19,456 KB
testcase_19 AC 178 ms
14,208 KB
testcase_20 AC 542 ms
19,200 KB
testcase_21 AC 522 ms
20,864 KB
testcase_22 AC 393 ms
18,816 KB
testcase_23 AC 463 ms
18,944 KB
testcase_24 AC 493 ms
18,944 KB
testcase_25 AC 110 ms
12,544 KB
testcase_26 AC 370 ms
15,872 KB
testcase_27 AC 269 ms
14,592 KB
testcase_28 AC 683 ms
21,120 KB
testcase_29 AC 701 ms
21,120 KB
testcase_30 AC 685 ms
21,248 KB
testcase_31 AC 682 ms
21,248 KB
testcase_32 AC 653 ms
21,248 KB
testcase_33 AC 665 ms
21,120 KB
testcase_34 AC 671 ms
21,248 KB
testcase_35 AC 650 ms
21,248 KB
testcase_36 AC 655 ms
21,248 KB
testcase_37 AC 679 ms
20,992 KB
testcase_38 AC 633 ms
21,120 KB
testcase_39 AC 663 ms
21,120 KB
testcase_40 AC 657 ms
21,248 KB
testcase_41 AC 654 ms
21,248 KB
testcase_42 AC 643 ms
21,120 KB
testcase_43 AC 634 ms
20,992 KB
testcase_44 AC 640 ms
21,248 KB
testcase_45 AC 656 ms
21,248 KB
testcase_46 AC 657 ms
21,248 KB
testcase_47 AC 653 ms
21,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - m
Syntax OK

ソースコード

diff #

n, m = gets.split(" ").map{|s| s.to_i}

a = []

n.times {
	a << gets.split(" ").map{|s| s.to_i}.sum
}

dp = Array.new(n+1) {Array.new(n+1, -Float::INFINITY)}

dp[0][0] = 0

1.upto(n) {|i|
	dp[i][0] = 0
	1.upto(n) {|j|
		dp[i][j] = [dp[i-1][j], dp[i-1][j-1] + (j % 2 == 1 ? a[i-1] : -a[i-1])].max
	}
}

puts dp[n].max
0