結果

問題 No.1231 Make a Multiple of Ten
ユーザー kokatsukokatsu
提出日時 2021-11-14 21:06:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 203,968 KB
実行使用メモリ 26,408 KB
最終ジャッジ日時 2023-09-04 14:58:51
合計ジャッジ時間 3,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 39 ms
12,764 KB
testcase_05 AC 32 ms
12,552 KB
testcase_06 AC 15 ms
6,204 KB
testcase_07 AC 41 ms
12,892 KB
testcase_08 AC 19 ms
10,204 KB
testcase_09 AC 9 ms
5,332 KB
testcase_10 AC 35 ms
11,852 KB
testcase_11 AC 43 ms
14,852 KB
testcase_12 AC 78 ms
22,668 KB
testcase_13 AC 79 ms
26,408 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 78 ms
25,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    auto A = readln.chomp.split.to!(int[]);

    auto dp = new int[][](N+1, 10);
    foreach (i; 0 .. N+1) {
        dp[i][] = -1;
    }
    dp[0][0] = 0;

    foreach (i, a; A) {
        dp[i+1][] = dp[i][];

        foreach (j; 0 .. 10) {
            if (dp[i][j] == -1) {
                continue;
            }

            long k = (a + j) % 10;
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+1);
        }
    }

    dp[N][0].writeln;
}
0