結果

問題 No.45 回転寿司
ユーザー hotwater2010hotwater2010
提出日時 2020-08-20 22:37:43
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 295 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-21 19:22:58
合計ジャッジ時間 4,139 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
12,544 KB
testcase_01 AC 96 ms
12,416 KB
testcase_02 AC 107 ms
12,544 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 78 ms
12,160 KB
testcase_06 AC 87 ms
12,544 KB
testcase_07 WA -
testcase_08 AC 79 ms
12,416 KB
testcase_09 AC 111 ms
12,544 KB
testcase_10 AC 84 ms
12,544 KB
testcase_11 AC 78 ms
12,416 KB
testcase_12 WA -
testcase_13 AC 75 ms
12,288 KB
testcase_14 WA -
testcase_15 AC 88 ms
12,288 KB
testcase_16 AC 80 ms
12,288 KB
testcase_17 AC 84 ms
12,416 KB
testcase_18 AC 82 ms
12,160 KB
testcase_19 AC 102 ms
12,672 KB
testcase_20 AC 78 ms
12,288 KB
testcase_21 AC 77 ms
12,160 KB
testcase_22 AC 78 ms
12,160 KB
testcase_23 AC 75 ms
12,288 KB
testcase_24 AC 75 ms
12,032 KB
testcase_25 AC 76 ms
12,160 KB
testcase_26 AC 88 ms
12,416 KB
testcase_27 AC 97 ms
12,544 KB
testcase_28 AC 88 ms
12,416 KB
testcase_29 WA -
testcase_30 AC 96 ms
12,672 KB
testcase_31 AC 74 ms
12,160 KB
testcase_32 WA -
testcase_33 AC 116 ms
12,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

$n = gets.to_i - 1
$v = gets.split.map(&:to_i)

def dfs(n, memo)
  return $v[0] if n==0
  return $v[1] if n==1

  tmp = -1
  (n-2).downto(0) do |i|
    tmp = [tmp, (memo[i] < 0 ? dfs(i, memo) : memo[i]) ].max
  end

  memo[n] = tmp + $v[n]
  return memo[n]
end

puts dfs($n, Array.new($n+1, -1))
0