結果
| 問題 |
No.372 It's automatic
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-23 09:36:38 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 947 ms / 6,000 ms |
| コード長 | 841 bytes |
| コンパイル時間 | 810 ms |
| コンパイル使用メモリ | 114,936 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 18:29:04 |
| 合計ジャッジ時間 | 13,139 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;
immutable int MOD = 10^^9+7;
void main() {
auto S = readln.chomp;
auto N = S.length;
auto M = readln.chomp.to!int;
int[20000][2] dp;
dp[0][0] = 0;
foreach (i; 0..N) {
int cur = i % 2;
int tar = 1 ^ cur;
int n = S[i] - '0';
memcpy(dp[tar].ptr, dp[cur].ptr, dp[cur].sizeof);
foreach (j; 0..M) {
dp[tar][(10*j+n)%M] += dp[cur][j];
dp[tar][(10*j+n)%M] %= MOD;
}
if (n != 0) {
dp[tar][n%M] += 1;
dp[tar][n%M] %= MOD;
}
}
int ans = S.count('0').to!int + dp[N%2][0];
ans %= MOD;
ans.writeln;
}