結果

問題 No.258 回転寿司(2)
ユーザー yuruhiyayuruhiya
提出日時 2020-05-10 11:04:06
言語 Crystal
(1.11.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 388 bytes
コンパイル時間 18,263 ms
コンパイル使用メモリ 256,348 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-09-13 10:35:39
合計ジャッジ時間 22,147 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,236 KB
testcase_01 AC 6 ms
5,168 KB
testcase_02 AC 4 ms
5,136 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 4 ms
5,000 KB
testcase_05 AC 4 ms
5,068 KB
testcase_06 AC 5 ms
5,120 KB
testcase_07 AC 3 ms
4,688 KB
testcase_08 AC 3 ms
5,056 KB
testcase_09 AC 3 ms
4,728 KB
testcase_10 AC 2 ms
4,552 KB
testcase_11 AC 3 ms
4,844 KB
testcase_12 AC 4 ms
4,960 KB
testcase_13 AC 3 ms
4,624 KB
testcase_14 AC 5 ms
5,168 KB
testcase_15 AC 3 ms
4,792 KB
testcase_16 AC 3 ms
4,700 KB
testcase_17 AC 3 ms
4,840 KB
testcase_18 AC 5 ms
5,072 KB
testcase_19 AC 3 ms
4,464 KB
testcase_20 AC 4 ms
5,136 KB
testcase_21 AC 6 ms
5,168 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,388 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,468 KB
testcase_26 AC 4 ms
5,148 KB
testcase_27 AC 3 ms
4,776 KB
testcase_28 AC 6 ms
5,164 KB
testcase_29 AC 3 ms
4,932 KB
testcase_30 AC 3 ms
4,468 KB
testcase_31 AC 2 ms
4,500 KB
testcase_32 AC 3 ms
4,832 KB
testcase_33 AC 5 ms
5,244 KB
testcase_34 AC 4 ms
5,100 KB
testcase_35 AC 4 ms
5,112 KB
testcase_36 AC 2 ms
4,568 KB
testcase_37 AC 2 ms
4,464 KB
testcase_38 AC 3 ms
4,784 KB
testcase_39 AC 3 ms
4,836 KB
testcase_40 AC 4 ms
5,076 KB
testcase_41 AC 5 ms
5,136 KB
testcase_42 AC 3 ms
4,736 KB
testcase_43 AC 3 ms
4,616 KB
testcase_44 AC 5 ms
5,108 KB
testcase_45 AC 4 ms
5,016 KB
testcase_46 AC 2 ms
4,444 KB
testcase_47 AC 4 ms
5,080 KB
testcase_48 AC 3 ms
4,588 KB
testcase_49 AC 3 ms
4,868 KB
testcase_50 AC 2 ms
4,520 KB
testcase_51 AC 4 ms
5,152 KB
testcase_52 AC 4 ms
5,196 KB
testcase_53 AC 3 ms
4,508 KB
testcase_54 AC 4 ms
5,096 KB
testcase_55 AC 6 ms
5,072 KB
testcase_56 AC 4 ms
5,172 KB
testcase_57 AC 2 ms
4,560 KB
testcase_58 AC 4 ms
5,008 KB
testcase_59 AC 5 ms
5,276 KB
testcase_60 AC 2 ms
4,596 KB
testcase_61 AC 4 ms
5,244 KB
testcase_62 AC 3 ms
4,784 KB
testcase_63 AC 4 ms
5,076 KB
testcase_64 AC 6 ms
5,240 KB
testcase_65 AC 4 ms
5,100 KB
testcase_66 AC 2 ms
4,508 KB
testcase_67 AC 4 ms
5,068 KB
testcase_68 AC 6 ms
5,008 KB
testcase_69 AC 4 ms
5,132 KB
testcase_70 AC 3 ms
4,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
a = read_line.split.map &.to_i

dp = Array.new(n, 0)
prev = Array.new(n, -1)

n.times do |i|
  if i < 2
    dp[i] = a[i]
  else
    pos = dp[0...i.pred].each_with_index.max[1]
    dp[i] = dp[pos] + a[i]
    prev[i] = pos
  end
end

ans = [dp.each_with_index.max[1]]
while prev[ans[-1]] != -1
  ans << prev[ans[-1]]
end
puts dp.max
puts ans.reverse.map(&.succ).join(' ')
0