結果

問題 No.1231 Make a Multiple of Ten
ユーザー y61mpnly61mpnl
提出日時 2020-10-03 14:37:40
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 3,384 ms
コンパイル使用メモリ 134,596 KB
実行使用メモリ 20,820 KB
最終ジャッジ日時 2023-09-25 05:13:47
合計ジャッジ時間 6,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 22 ms
11,552 KB
testcase_05 AC 18 ms
10,448 KB
testcase_06 AC 10 ms
6,408 KB
testcase_07 AC 21 ms
11,892 KB
testcase_08 AC 12 ms
8,404 KB
testcase_09 AC 7 ms
5,168 KB
testcase_10 AC 20 ms
10,920 KB
testcase_11 AC 23 ms
12,476 KB
testcase_12 AC 41 ms
19,924 KB
testcase_13 AC 43 ms
20,716 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 42 ms
20,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
    int n;
    scanf("%d", &n);
    ll a[n];
    for(int i=0; i<n; i++){
        scanf("%ld", &a[i]);
        a[i] %= 10;
    }

    ll dp[1+n][10];
    for(int i=0; i<=n; i++) for(int j=0; j<10; j++) dp[i][j] = -1;
    dp[0][0] = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            if(dp[i][j]<0) continue;
            dp[i+1][j] = std::max(dp[i+1][j], dp[i][j]);
            dp[i+1][(j+a[i])%10] = std::max(dp[i+1][(j+a[i])%10], dp[i][j]+1);
        }
    }
    printf("%ld\n", dp[n][0]);
    return 0;
}
0