結果

問題 No.1231 Make a Multiple of Ten
ユーザー simansiman
提出日時 2020-09-21 15:33:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,389 ms / 2,000 ms
コード長 425 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 28,464 KB
最終ジャッジ日時 2023-09-06 17:08:37
合計ジャッジ時間 9,889 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,248 KB
testcase_01 AC 81 ms
15,060 KB
testcase_02 AC 79 ms
15,264 KB
testcase_03 AC 79 ms
15,160 KB
testcase_04 AC 555 ms
21,196 KB
testcase_05 AC 541 ms
20,348 KB
testcase_06 AC 273 ms
17,228 KB
testcase_07 AC 617 ms
21,764 KB
testcase_08 AC 481 ms
18,632 KB
testcase_09 AC 205 ms
16,232 KB
testcase_10 AC 665 ms
20,728 KB
testcase_11 AC 759 ms
22,048 KB
testcase_12 AC 1,389 ms
27,572 KB
testcase_13 AC 1,238 ms
28,336 KB
testcase_14 AC 79 ms
15,348 KB
testcase_15 AC 1,140 ms
28,464 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

m = A.sum % 10
nodes = [m]
min_dist = Hash.new(Float::INFINITY)
min_dist[m] = 0

A.each do |a|
  m = a % 10

  nodes.each do |n|
    next if min_dist[n] == Float::INFINITY

    nm = (n - m) % 10
    dist = min_dist[n] + 1

    next if min_dist[nm] <= dist
    min_dist[nm] = dist

    nodes << nm
  end
end

if min_dist[0] == Float::INFINITY
  puts 0
else
  puts N - min_dist[0]
end
0