結果
問題 | No.260 世界のなんとか3 |
ユーザー | te-sh |
提出日時 | 2017-06-01 12:21:24 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 466 ms / 2,000 ms |
コード長 | 2,128 bytes |
コンパイル時間 | 901 ms |
コンパイル使用メモリ | 87,692 KB |
実行使用メモリ | 35,980 KB |
最終ジャッジ日時 | 2023-09-03 13:49:00 |
合計ジャッジ時間 | 7,303 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 374 ms
35,980 KB |
testcase_04 | AC | 375 ms
35,652 KB |
testcase_05 | AC | 72 ms
8,772 KB |
testcase_06 | AC | 48 ms
6,676 KB |
testcase_07 | AC | 255 ms
24,136 KB |
testcase_08 | AC | 179 ms
18,324 KB |
testcase_09 | AC | 98 ms
11,812 KB |
testcase_10 | AC | 289 ms
28,780 KB |
testcase_11 | AC | 272 ms
25,948 KB |
testcase_12 | AC | 164 ms
17,188 KB |
testcase_13 | AC | 46 ms
6,416 KB |
testcase_14 | AC | 246 ms
23,592 KB |
testcase_15 | AC | 66 ms
9,496 KB |
testcase_16 | AC | 216 ms
22,096 KB |
testcase_17 | AC | 170 ms
17,424 KB |
testcase_18 | AC | 164 ms
16,988 KB |
testcase_19 | AC | 214 ms
22,620 KB |
testcase_20 | AC | 153 ms
15,476 KB |
testcase_21 | AC | 131 ms
13,860 KB |
testcase_22 | AC | 244 ms
24,320 KB |
testcase_23 | AC | 25 ms
4,620 KB |
testcase_24 | AC | 188 ms
19,124 KB |
testcase_25 | AC | 239 ms
19,088 KB |
testcase_26 | AC | 146 ms
19,748 KB |
testcase_27 | AC | 1 ms
4,376 KB |
testcase_28 | AC | 285 ms
35,076 KB |
testcase_29 | AC | 466 ms
35,940 KB |
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string; const p = 10 ^^ 9 + 7; alias FactorRing!(p, true) pint; alias FactorRing!p mint; void main() { auto rd = readln.split.map!(s => s.map!(c => (c - '0').to!int).array), a = rd[0], b = rd[1]; auto r = mint(calc!true(b).v) - mint(calc!false(a).v); writeln(r.v); } auto calc(bool includeMax)(int[] ai) { auto n = ai.length; auto dp = new pint[][][][][](n+1, 2, 2, 3, 8); dp[0][0][0][0][0] = 1; foreach (i; 0..n) foreach (j; 0..2) foreach (k; 0..2) foreach (l; 0..3) foreach (m; 0..8) { int lim = j ? 9 : ai[i]; foreach (d; 0..lim+1) dp[i+1][j || d < lim][k || d == 3][(l + d) % 3][(m * 10 + d) % 8] += dp[i][j][k][l][m]; } auto r = pint(0); auto jMin = includeMax ? 0 : 1; foreach (j; jMin..2) foreach (k; 0..2) foreach (l; 0..3) foreach (m; 1..8) if (k == 1 || l == 0) r += dp[$-1][j][k][l][m]; return r; } struct FactorRing(int m, bool pos = false) { long v; //@property int toInt() { return v.to!int; } //alias toInt this; this(T)(T _v) { v = mod(_v); } ref FactorRing!(m, pos) opAssign(int _v) { v = mod(_v); return this; } pure auto mod(long _v) const { static if (pos) return _v % m; else return (_v % m + m) % m; } pure auto opBinary(string op: "+")(long rhs) const { return FactorRing!(m, pos)(v + rhs); } pure auto opBinary(string op: "-")(long rhs) const { return FactorRing!(m, pos)(v - rhs); } pure auto opBinary(string op: "*")(long rhs) const { return FactorRing!(m, pos)(v * rhs); } pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.v); } auto opOpAssign(string op: "+")(long rhs) { v = mod(v + rhs); } auto opOpAssign(string op: "-")(long rhs) { v = mod(v - rhs); } auto opOpAssign(string op: "*")(long rhs) { v = mod(v * rhs); } auto opOpAssign(string op)(FactorRing!(m, pos) rhs) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.v); } }