結果

問題 No.1231 Make a Multiple of Ten
ユーザー shi-moshi-mo
提出日時 2020-09-28 18:05:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 678 ms / 2,000 ms
コード長 398 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 32,004 KB
最終ジャッジ日時 2023-09-15 02:15:53
合計ジャッジ時間 6,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,272 KB
testcase_01 AC 82 ms
15,048 KB
testcase_02 AC 82 ms
15,012 KB
testcase_03 AC 81 ms
15,124 KB
testcase_04 AC 353 ms
21,920 KB
testcase_05 AC 317 ms
23,008 KB
testcase_06 AC 174 ms
19,000 KB
testcase_07 AC 364 ms
24,176 KB
testcase_08 AC 244 ms
20,832 KB
testcase_09 AC 136 ms
17,676 KB
testcase_10 AC 336 ms
22,452 KB
testcase_11 AC 385 ms
24,628 KB
testcase_12 AC 638 ms
31,256 KB
testcase_13 AC 663 ms
31,964 KB
testcase_14 AC 81 ms
15,124 KB
testcase_15 AC 678 ms
32,004 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

gets # discard N
a = gets.split.map(&:to_i).map{|ai| ai % 10 }

dp = [-1] * 10
dp[0] = 0
a.each do |ai|
  next_dp = [-1] * 10
  10.times do |j|
    next if dp[j] < 0 # cannot make j

    if next_dp[j] < dp[j] # use a[0]..a[i-1]
      next_dp[j] = dp[j]
    end
    r = (j + ai) % 10
    if next_dp[r] < (dp[j] + 1) # use a[i]
      next_dp[r] = dp[j] + 1
    end
  end
  dp = next_dp
end
puts dp[0]
0