結果

問題 No.1231 Make a Multiple of Ten
ユーザー FromBooskaFromBooska
提出日時 2023-09-24 10:53:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 499 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 150,092 KB
最終ジャッジ日時 2023-09-24 10:53:40
合計ジャッジ時間 5,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,360 KB
testcase_01 AC 71 ms
71,556 KB
testcase_02 AC 71 ms
71,236 KB
testcase_03 AC 72 ms
71,348 KB
testcase_04 AC 164 ms
97,132 KB
testcase_05 AC 156 ms
97,060 KB
testcase_06 AC 114 ms
85,900 KB
testcase_07 AC 166 ms
97,036 KB
testcase_08 AC 126 ms
90,728 KB
testcase_09 AC 102 ms
82,324 KB
testcase_10 AC 158 ms
97,156 KB
testcase_11 AC 180 ms
97,228 KB
testcase_12 AC 259 ms
135,608 KB
testcase_13 AC 287 ms
149,880 KB
testcase_14 AC 71 ms
71,048 KB
testcase_15 AC 287 ms
150,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 部分和dpの変形かな
# dp[i番目まで見て][j mod 10]の最高枚数
# aはmod 10する

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

INF = 10**20
dp = [[-INF]*10 for i in range(N+1)]
dp[0][0] = 0

for i in range(1, N+1):
    num = A[i-1]%10
    # 使わない
    for j in range(10):
        dp[i][j] = dp[i-1][j]
    # 使う
    for j in range(10):
        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