結果

問題 No.45 回転寿司
ユーザー shi-moshi-mo
提出日時 2016-03-28 12:31:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 309 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,272 KB
実行使用メモリ 38,244 KB
最終ジャッジ日時 2023-08-27 14:38:46
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
20,764 KB
testcase_01 AC 95 ms
25,348 KB
testcase_02 AC 103 ms
32,352 KB
testcase_03 AC 106 ms
33,416 KB
testcase_04 AC 95 ms
26,764 KB
testcase_05 AC 89 ms
15,576 KB
testcase_06 AC 94 ms
23,152 KB
testcase_07 AC 101 ms
32,340 KB
testcase_08 AC 87 ms
17,656 KB
testcase_09 AC 103 ms
32,508 KB
testcase_10 AC 91 ms
20,980 KB
testcase_11 AC 86 ms
17,328 KB
testcase_12 AC 102 ms
32,292 KB
testcase_13 AC 85 ms
15,288 KB
testcase_14 AC 85 ms
15,048 KB
testcase_15 AC 93 ms
22,012 KB
testcase_16 AC 89 ms
18,232 KB
testcase_17 AC 91 ms
20,256 KB
testcase_18 AC 89 ms
18,492 KB
testcase_19 AC 101 ms
30,400 KB
testcase_20 AC 84 ms
15,148 KB
testcase_21 AC 86 ms
15,272 KB
testcase_22 AC 82 ms
15,120 KB
testcase_23 AC 84 ms
15,280 KB
testcase_24 AC 82 ms
15,068 KB
testcase_25 AC 83 ms
15,228 KB
testcase_26 AC 92 ms
21,656 KB
testcase_27 AC 99 ms
30,348 KB
testcase_28 AC 92 ms
22,732 KB
testcase_29 AC 96 ms
28,328 KB
testcase_30 AC 98 ms
29,020 KB
testcase_31 AC 81 ms
15,072 KB
testcase_32 AC 83 ms
15,032 KB
testcase_33 AC 108 ms
38,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
v = [nil] + gets.chomp!.split.map(&:to_i)

dp_a = [ 0, v[1] ] # scores include i-th dish
dp_b = [ 0, 0    ] # scores without i-th dish

2.upto(n) do |i|
  dp_a[i] = v[i] + (dp_a[1..(i-2)] + dp_b[1..(i-1)]).max
  dp_b[i] = (dp_a[1..(i-1)] + dp_b[1..(i-1)]).max
end

puts [ dp_a[n], dp_b[n] ].max
0