結果

問題 No.189 SUPER HAPPY DAY
ユーザー noriocnorioc
提出日時 2019-06-14 01:04:43
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,563 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 92,732 KB
実行使用メモリ 10,088 KB
最終ジャッジ日時 2023-09-04 01:41:30
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 15 ms
5,468 KB
testcase_14 AC 21 ms
6,456 KB
testcase_15 AC 22 ms
5,664 KB
testcase_16 AC 26 ms
6,184 KB
testcase_17 AC 27 ms
6,196 KB
testcase_18 AC 21 ms
5,936 KB
testcase_19 AC 29 ms
7,208 KB
testcase_20 AC 9 ms
5,100 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 20 ms
5,968 KB
testcase_24 AC 20 ms
5,872 KB
testcase_25 AC 39 ms
10,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 9;

void add(T)(ref T a, T b) { a = (a + b) % MOD; }

int[] _calc(string s) {
    int n = cast(int)s.length;
    int maxSum = n * 10; // 各桁の和の最大値(大きめにとっている)

    auto dp = new int[][][](n + 1, 2, maxSum + 10);
    // dp[i][j][k]
    // i: 上から i 桁目まで
    // j: n 未満か
    // k: 桁の和

    dp[0][0][0] = 1;
    foreach (i; 0..n) {
        foreach (j; 0..2) {
            foreach (k; 0..maxSum) {
                int d = s[i] - '0';
                int lim = j ? 9 : d;
                foreach (m; 0..lim+1) {
                    add(dp[i + 1][j || m < lim][k + m], dp[i][j][k]);
                }
            }
        }
    }

    // 和のパターン数
    auto ret = new int[maxSum];
    foreach (k; 0..maxSum) {
        ret[k] = (ret[k] + dp[n][0][k] + dp[n][1][k]) % MOD;
    }
    return ret;
}

long calc(string m, string d) {
    auto a = _calc(m);
    auto b = _calc(d);

    long ans = 0;
    for (int i = 1; i < min(a.length, b.length); i++) {
        add(ans, 1L * a[i] * b[i]);
    }
    return ans;
}

void main() {
    string m, d; scan(m, d);
    writeln(calc(m, d));
}

0