結果

問題 No.258 回転寿司(2)
ユーザー koyoprokoyopro
提出日時 2019-12-13 23:22:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 11,364 KB
実行使用メモリ 17,072 KB
最終ジャッジ日時 2023-09-10 05:25:51
合計ジャッジ時間 12,177 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
17,036 KB
testcase_01 AC 86 ms
16,860 KB
testcase_02 AC 86 ms
15,788 KB
testcase_03 AC 83 ms
15,076 KB
testcase_04 AC 85 ms
15,620 KB
testcase_05 AC 85 ms
15,448 KB
testcase_06 AC 85 ms
16,468 KB
testcase_07 AC 83 ms
15,044 KB
testcase_08 AC 85 ms
15,552 KB
testcase_09 AC 83 ms
15,044 KB
testcase_10 AC 83 ms
15,092 KB
testcase_11 AC 85 ms
15,156 KB
testcase_12 AC 82 ms
15,592 KB
testcase_13 AC 83 ms
15,096 KB
testcase_14 AC 86 ms
16,232 KB
testcase_15 AC 82 ms
15,264 KB
testcase_16 AC 83 ms
15,184 KB
testcase_17 AC 81 ms
15,300 KB
testcase_18 AC 86 ms
16,484 KB
testcase_19 AC 82 ms
15,148 KB
testcase_20 AC 84 ms
15,948 KB
testcase_21 AC 84 ms
16,492 KB
testcase_22 AC 80 ms
15,152 KB
testcase_23 AC 80 ms
15,296 KB
testcase_24 AC 80 ms
15,276 KB
testcase_25 AC 81 ms
15,344 KB
testcase_26 AC 85 ms
15,600 KB
testcase_27 AC 83 ms
15,272 KB
testcase_28 AC 88 ms
16,868 KB
testcase_29 AC 86 ms
15,592 KB
testcase_30 AC 84 ms
15,044 KB
testcase_31 AC 83 ms
15,156 KB
testcase_32 AC 83 ms
15,160 KB
testcase_33 AC 86 ms
16,000 KB
testcase_34 AC 85 ms
15,444 KB
testcase_35 AC 85 ms
15,304 KB
testcase_36 AC 83 ms
15,052 KB
testcase_37 AC 83 ms
15,312 KB
testcase_38 AC 84 ms
15,572 KB
testcase_39 AC 84 ms
15,364 KB
testcase_40 AC 85 ms
15,596 KB
testcase_41 AC 85 ms
16,240 KB
testcase_42 AC 84 ms
15,308 KB
testcase_43 AC 82 ms
15,044 KB
testcase_44 AC 85 ms
16,332 KB
testcase_45 AC 84 ms
15,840 KB
testcase_46 AC 81 ms
15,156 KB
testcase_47 AC 84 ms
15,724 KB
testcase_48 AC 84 ms
15,128 KB
testcase_49 AC 82 ms
15,136 KB
testcase_50 AC 82 ms
15,048 KB
testcase_51 AC 84 ms
15,416 KB
testcase_52 AC 85 ms
15,440 KB
testcase_53 AC 80 ms
15,332 KB
testcase_54 AC 83 ms
15,728 KB
testcase_55 AC 85 ms
16,892 KB
testcase_56 AC 84 ms
15,724 KB
testcase_57 AC 81 ms
15,156 KB
testcase_58 AC 85 ms
15,556 KB
testcase_59 AC 87 ms
16,636 KB
testcase_60 AC 83 ms
15,348 KB
testcase_61 AC 86 ms
15,920 KB
testcase_62 AC 82 ms
15,200 KB
testcase_63 AC 85 ms
15,776 KB
testcase_64 AC 86 ms
17,072 KB
testcase_65 AC 85 ms
15,824 KB
testcase_66 AC 83 ms
15,312 KB
testcase_67 AC 86 ms
16,232 KB
testcase_68 AC 87 ms
16,444 KB
testcase_69 AC 84 ms
15,884 KB
testcase_70 AC 81 ms
15,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

N = gets.to_i
POINTS = gets.split.map(&:to_i)

DP = {}
ARRAY = {}

DP[-1] = 0
ARRAY[-1] = []

DP[0] = POINTS[0]
ARRAY[0] = [0]

DP[1] = POINTS[1]
ARRAY[1] = [1]

(2...N).each do |i|
  point = POINTS[i]
  i1 = i - 3
  i2 = i - 2
  index = DP[i1] > DP[i2] ? i1 : i2
  DP[i] = DP[index] + point
  ARRAY[i] = ARRAY[index] + [i]
end

index = DP[N - 1] > DP[N - 2] ? N - 1 : N - 2
puts DP[index]
puts ARRAY[index].map { |i| i+1 }.join(' ')
0