結果
問題 | No.189 SUPER HAPPY DAY |
ユーザー |
![]() |
提出日時 | 2019-06-14 01:04:43 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 36 ms / 5,000 ms |
コード長 | 1,563 bytes |
コンパイル時間 | 686 ms |
コンパイル使用メモリ | 104,320 KB |
実行使用メモリ | 10,516 KB |
最終ジャッジ日時 | 2024-06-22 01:42:43 |
合計ジャッジ時間 | 1,525 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
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));}