Submission #1604386
Source Code Expand
import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } int calc(string s, int d) { const MOD = 1_000_000_007; int n = cast(int) s.length; auto dp = new int[][][](n + 1, 2, d); // dp[i][j][k] // i: 上から i 桁目まで // j: n 未満か // k: mod d dp[0][0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < d; k++) { int lim = j == 1 ? 9 : s[i] - '0'; for (int m = 0; m <= lim; m++) { (dp[i + 1][j || m < lim][(k + m) % d] += dp[i][j][k]) %= MOD; } } } } int ans = 0; for (int j = 0; j < 2; j++) { ans = (ans + dp[n][j][0]) % MOD; } return ans - 1; // -1 は 0 の分 } void main() { int d = readint; string s = readln.chomp; writeln(calc(s, d)); }
Submission Info
Submission Time | |
---|---|
Task | E - 数 |
User | noriok |
Language | D (DMD64 v2.070.1) |
Score | 4 |
Code Size | 1145 Byte |
Status | AC |
Exec Time | 127 ms |
Memory | 13308 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 4 / 4 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 00, 01, 02, 90, 91 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00 | AC | 2 ms | 380 KB |
01 | AC | 78 ms | 7548 KB |
02 | AC | 127 ms | 13308 KB |
90 | AC | 1 ms | 256 KB |
91 | AC | 1 ms | 256 KB |