結果

問題 No.1231 Make a Multiple of Ten
コンテスト
ユーザー mkawa2
提出日時 2021-08-14 16:54:32
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 1,043 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 335 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 36,128 KB
最終ジャッジ日時 2026-04-21 01:06:20
合計ジャッジ時間 3,264 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7


n = II()
aa = LI()
cnt = [0]*10
r = 0
for a in aa:
    a %= 10
    cnt[a] += 1
    r += a
    r %= 10

def chmin(i, j, val):
    if val < dp[i][j]: dp[i][j] = val

dp = [[inf]*10 for _ in range(10)]
dp[0][0] = 0
for i in range(1, 10):
    for j in range(10):
        pre = dp[i-1][j]
        if pre == inf: continue
        for c in range(min(10, cnt[i]+1)):
            chmin(i, (j+c*i)%10, pre+c)

ans = n-dp[9][r]
print(ans)
0