結果

問題 No.1231 Make a Multiple of Ten
ユーザー FromBooskaFromBooska
提出日時 2023-03-12 08:43:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 118,292 KB
最終ジャッジ日時 2023-10-18 10:29:03
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,392 KB
testcase_01 AC 37 ms
53,392 KB
testcase_02 AC 38 ms
53,392 KB
testcase_03 AC 38 ms
53,392 KB
testcase_04 AC 115 ms
94,000 KB
testcase_05 AC 110 ms
92,680 KB
testcase_06 AC 81 ms
83,424 KB
testcase_07 AC 116 ms
95,456 KB
testcase_08 AC 97 ms
89,972 KB
testcase_09 AC 62 ms
73,664 KB
testcase_10 AC 112 ms
94,068 KB
testcase_11 AC 120 ms
95,384 KB
testcase_12 AC 200 ms
108,272 KB
testcase_13 AC 211 ms
118,196 KB
testcase_14 AC 39 ms
53,392 KB
testcase_15 AC 211 ms
118,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ABC281Dと近い
# 2次元dp
# dp[i][j] i番目まで見て、j mod 10、の最大枚数

N = int(input())
A = list(map(int, input().split()))

INF = 10**10
dp = [[-INF]*10 for i in range(N+1)]
dp[0][0] = 0
 
for i in range(1, N+1):
    num = A[i-1]
    for j in range(10):
        # not using i-th
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        # using i-th
        dp[i][(j+num)%10] = max(dp[i][(j+num)%10], dp[i-1][j]+1)
    #print(dp[i])
    
ans = dp[N][0]
print(ans)
0