結果
問題 | No.260 世界のなんとか3 |
ユーザー | ikd |
提出日時 | 2018-10-04 19:34:51 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,985 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 87,288 KB |
実行使用メモリ | 29,556 KB |
最終ジャッジ日時 | 2023-09-03 21:02:02 |
合計ジャッジ時間 | 3,260 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 21 ms
8,544 KB |
testcase_06 | AC | 14 ms
6,432 KB |
testcase_07 | AC | 82 ms
21,912 KB |
testcase_08 | AC | 54 ms
17,636 KB |
testcase_09 | AC | 30 ms
10,444 KB |
testcase_10 | AC | 86 ms
23,292 KB |
testcase_11 | AC | 80 ms
24,212 KB |
testcase_12 | AC | 47 ms
16,556 KB |
testcase_13 | AC | 12 ms
5,904 KB |
testcase_14 | WA | - |
testcase_15 | AC | 19 ms
7,772 KB |
testcase_16 | AC | 62 ms
18,040 KB |
testcase_17 | AC | 49 ms
15,344 KB |
testcase_18 | WA | - |
testcase_19 | AC | 60 ms
18,832 KB |
testcase_20 | AC | 42 ms
15,224 KB |
testcase_21 | WA | - |
testcase_22 | AC | 72 ms
21,428 KB |
testcase_23 | AC | 8 ms
4,376 KB |
testcase_24 | AC | 54 ms
17,616 KB |
testcase_25 | AC | 54 ms
19,416 KB |
testcase_26 | AC | 53 ms
18,692 KB |
testcase_27 | AC | 1 ms
4,380 KB |
testcase_28 | AC | 105 ms
29,456 KB |
testcase_29 | WA | - |
ソースコード
void main() { import std.stdio, std.string, std.conv, std.algorithm; auto args = readln.split.to!(char[][]); const int MOD = 10 ^^ 9 + 7; int solve(char[] n) { int[] pow10mod3 = [1]; int[] pow10mod8 = [1]; foreach (_; 0 .. n.length) { pow10mod3 ~= pow10mod3[$ - 1] * 10 % 3; pow10mod8 ~= pow10mod8[$ - 1] * 10 % 8; } auto memo = new int[][][][][](n.length + 1, 2, 2, 3, 8); afill(memo, -1); int f(size_t i, bool less, bool ok, int mod3, int mod8) { if (memo[i][less][ok][mod3][mod8] >= 0) { return memo[i][less][ok][mod3][mod8]; } if (i == n.length) { return (ok || mod3 == 0) && (mod8 > 0); } else { auto digit = less ? 9 : n[i] - '0'; int ret = 0; for (int d = 0; d <= digit; d++) { auto l = less || (d < digit); auto o = ok || (d == 3); auto m3 = (mod3 + d * pow10mod3[n.length - i - 1]) % 3; auto m8 = (mod8 + d * pow10mod8[n.length - i - 1]) % 8; (ret += f(i + 1, l, o, m3, m8)) %= MOD; } return memo[i][less][ok][mod3][mod8] = ret; } } return f(0, 0, 0, 0, 0); } bool yes(char[] n) { auto m8 = reduce!((res, ch) => (res + (ch - '0')) % 8)(0, n); if (m8 == 0) { return false; } else if (n.count('3') > 0) { return true; } else { auto m3 = reduce!((res, ch) => (res + (ch - '0')) % 3)(0, n); return m3 == 0; } } auto res = (solve(args[1]) - solve(args[0]) + MOD) % MOD; writeln((res + yes(args[0])) % MOD); } void afill(Range, Type)(ref Range r, Type v) { static if (is(typeof(r) == Type[])) { foreach (ref e; r) { e = v; } } else { foreach (ref _r; r) { afill(_r, v); } } } 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)); }