結果

問題 No.258 回転寿司(2)
ユーザー simansiman
提出日時 2021-08-31 11:03:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 15,376 KB
最終ジャッジ日時 2023-08-16 14:59:32
合計ジャッジ時間 13,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
15,156 KB
testcase_01 AC 143 ms
15,144 KB
testcase_02 AC 104 ms
15,072 KB
testcase_03 AC 79 ms
15,092 KB
testcase_04 AC 90 ms
15,272 KB
testcase_05 AC 92 ms
15,148 KB
testcase_06 AC 129 ms
15,032 KB
testcase_07 AC 86 ms
15,152 KB
testcase_08 AC 92 ms
15,108 KB
testcase_09 AC 85 ms
15,272 KB
testcase_10 AC 80 ms
15,376 KB
testcase_11 AC 86 ms
15,312 KB
testcase_12 AC 91 ms
15,076 KB
testcase_13 AC 83 ms
15,196 KB
testcase_14 AC 121 ms
15,260 KB
testcase_15 AC 84 ms
15,196 KB
testcase_16 AC 84 ms
15,048 KB
testcase_17 AC 85 ms
15,032 KB
testcase_18 AC 133 ms
15,152 KB
testcase_19 AC 80 ms
15,140 KB
testcase_20 AC 109 ms
15,156 KB
testcase_21 AC 125 ms
15,104 KB
testcase_22 AC 79 ms
15,148 KB
testcase_23 AC 79 ms
15,160 KB
testcase_24 AC 79 ms
15,304 KB
testcase_25 AC 81 ms
15,248 KB
testcase_26 AC 103 ms
15,148 KB
testcase_27 AC 85 ms
15,260 KB
testcase_28 AC 140 ms
15,316 KB
testcase_29 AC 87 ms
15,312 KB
testcase_30 AC 80 ms
15,312 KB
testcase_31 AC 80 ms
15,304 KB
testcase_32 AC 86 ms
15,308 KB
testcase_33 AC 114 ms
15,272 KB
testcase_34 AC 98 ms
15,032 KB
testcase_35 AC 96 ms
15,276 KB
testcase_36 AC 80 ms
15,272 KB
testcase_37 AC 81 ms
15,144 KB
testcase_38 AC 89 ms
15,296 KB
testcase_39 AC 91 ms
15,192 KB
testcase_40 AC 107 ms
15,104 KB
testcase_41 AC 118 ms
15,160 KB
testcase_42 AC 84 ms
15,108 KB
testcase_43 AC 81 ms
15,228 KB
testcase_44 AC 122 ms
15,280 KB
testcase_45 AC 107 ms
15,316 KB
testcase_46 AC 78 ms
15,304 KB
testcase_47 AC 108 ms
15,148 KB
testcase_48 AC 85 ms
15,332 KB
testcase_49 AC 84 ms
15,260 KB
testcase_50 AC 79 ms
15,048 KB
testcase_51 AC 100 ms
15,296 KB
testcase_52 AC 95 ms
15,312 KB
testcase_53 AC 79 ms
15,088 KB
testcase_54 AC 108 ms
15,140 KB
testcase_55 AC 142 ms
15,196 KB
testcase_56 AC 108 ms
15,156 KB
testcase_57 AC 80 ms
15,068 KB
testcase_58 AC 94 ms
15,260 KB
testcase_59 AC 132 ms
15,140 KB
testcase_60 AC 81 ms
15,296 KB
testcase_61 AC 114 ms
15,344 KB
testcase_62 AC 86 ms
15,032 KB
testcase_63 AC 102 ms
15,232 KB
testcase_64 AC 139 ms
15,356 KB
testcase_65 AC 103 ms
15,072 KB
testcase_66 AC 79 ms
15,036 KB
testcase_67 AC 121 ms
15,160 KB
testcase_68 AC 122 ms
15,160 KB
testcase_69 AC 111 ms
15,152 KB
testcase_70 AC 82 ms
15,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

dp = Array.new(N, 0)
path = Array.new(N, -1)

max_v = 0
start = -1

N.times do |i|
  if dp[i] < V[i]
    dp[i] = V[i]
    path[i] = -1
  end

  (i + 2).upto(N - 1) do |j|
    nv = dp[i] + V[j]
    next if dp[j] >= nv

    dp[j] = nv
    path[j] = i
  end

  if max_v < dp[i]
    max_v = dp[i]
    start = i
  end
end

cur = start
ans = [cur + 1]

while path[cur] != -1
  cur = path[cur]
  ans << cur + 1
end

puts max_v
puts ans.reverse.join(' ')
0