結果
| 問題 |
No.189 SUPER HAPPY DAY
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-10-05 04:42:05 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 5,000 ms |
| コード長 | 1,197 bytes |
| コンパイル時間 | 678 ms |
| コンパイル使用メモリ | 94,976 KB |
| 実行使用メモリ | 15,060 KB |
| 最終ジャッジ日時 | 2024-06-13 01:45:54 |
| 合計ジャッジ時間 | 2,159 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto args = readln.split.to!(string[]);
const long mod = 10 ^^ 9 + 9;
long[][] solve(string n) {
auto dp = new long[][][](n.length + 1, 2, n.length * 10);
dp[0][0][0] = 1;
foreach (i; 0 .. n.length) {
foreach (l; 0 .. 2) {
foreach (s; 0 .. (n.length * 10)) {
auto d = l ? 9 : n[i] - '0';
for (int digit = 0; digit <= d; digit++) {
auto less = l || (digit < d);
auto sum = s + digit;
if (sum < n.length * 10) {
(dp[i + 1][less][sum] += dp[i][l][s]) %= mod;
}
}
}
}
}
return dp[n.length];
}
auto dp1 = solve(args[0]), dp2 = solve(args[1]);
long tot = 0;
foreach (i; 0 .. 2) {
foreach (j; 0 .. 2) {
foreach (s; 1 .. min(dp1[i].length, dp2[j].length)) {
(tot += dp1[i][s] * dp2[j][s] % mod) %= mod;
}
}
}
writeln(tot);
}
void rd(T...)(ref T x) {
import std.stdio : readln;
import std.string : split;
import std.conv : to;
auto l = readln.split;
assert(l.length == x.length);
foreach (i, ref e; x)
e = l[i].to!(typeof(e));
}
ikd