結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2018-10-05 08:11:38 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 1,239 ms / 6,000 ms |
| コード長 | 858 bytes |
| コンパイル時間 | 611 ms |
| コンパイル使用メモリ | 100,640 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 01:49:44 |
| 合計ジャッジ時間 | 16,274 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
void main() {
import std.stdio, std.string, std.conv, std.algorithm;
auto s = readln.chomp.to!(char[]);
int m;
rd(m);
const int mod = 10 ^^ 9 + 7;
int zero = 0;
auto dp = new int[][](2, m);
foreach (i; 0 .. s.length) {
auto cur = i % 2, nex = cur ^ 1;
auto curDP = dp[cur], nexDP = dp[nex];
auto d = s[i] - '0';
foreach (j; 0 .. m) {
nexDP[j] = curDP[j];
}
foreach (j; 0 .. m) {
(nexDP[(j * 10 + d) % m] += curDP[j]) %= mod;
}
if (d == 0) {
(zero += 1) %= mod;
} else {
(nexDP[d % m] += 1) %= mod;
}
}
writeln((dp[(s.length) % 2][0] + zero) % mod);
}
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