結果

問題 No.1231 Make a Multiple of Ten
ユーザー simansiman
提出日時 2020-09-21 15:34:17
言語 Ruby
(3.2.2)
結果
AC  
実行時間 997 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 11,560 KB
実行使用メモリ 28,528 KB
最終ジャッジ日時 2023-09-06 17:08:47
合計ジャッジ時間 7,827 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,060 KB
testcase_01 AC 79 ms
15,264 KB
testcase_02 AC 79 ms
15,052 KB
testcase_03 AC 79 ms
15,224 KB
testcase_04 AC 436 ms
21,420 KB
testcase_05 AC 419 ms
20,472 KB
testcase_06 AC 224 ms
17,012 KB
testcase_07 AC 469 ms
21,720 KB
testcase_08 AC 368 ms
18,400 KB
testcase_09 AC 173 ms
16,256 KB
testcase_10 AC 500 ms
20,676 KB
testcase_11 AC 585 ms
22,008 KB
testcase_12 AC 997 ms
27,664 KB
testcase_13 AC 900 ms
28,528 KB
testcase_14 AC 77 ms
15,324 KB
testcase_15 AC 834 ms
28,412 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

m = A.sum % 10
nodes = [m]
min_dist = Array.new(10, 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