結果

問題 No.1231 Make a Multiple of Ten
ユーザー 👑 rin204rin204
提出日時 2022-01-18 21:49:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 107,520 KB
最終ジャッジ日時 2024-05-02 19:32:14
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,224 KB
testcase_01 AC 34 ms
52,096 KB
testcase_02 AC 35 ms
52,224 KB
testcase_03 AC 34 ms
51,968 KB
testcase_04 AC 63 ms
81,280 KB
testcase_05 AC 66 ms
78,848 KB
testcase_06 AC 51 ms
66,816 KB
testcase_07 AC 65 ms
83,200 KB
testcase_08 AC 53 ms
70,272 KB
testcase_09 AC 46 ms
63,872 KB
testcase_10 AC 64 ms
80,384 KB
testcase_11 AC 69 ms
84,224 KB
testcase_12 AC 95 ms
107,520 KB
testcase_13 AC 101 ms
101,760 KB
testcase_14 AC 36 ms
52,224 KB
testcase_15 AC 107 ms
102,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
tot = sum(A)
x = tot % 10
cnt = [0] * 10
for a in A:
    cnt[a % 10] += 1

inf = 1 << 30    
dp = [[inf] * 10 for _ in range(10)]
dp[0][0] = 0
for i, c in enumerate(cnt):
    if i == 0:
        continue
    
    c = min(c, 9)
    for j in range(c + 1):
        for k in range(10):
            nj = (i * j + k) % 10
            dp[i][nj] = min(dp[i][nj], dp[i - 1][k] + j)
        
min_ = inf
for i in range(10):
    min_ = min(min_, dp[i][x])
print(n - min_)

0