結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | Min_25 |
提出日時 | 2015-12-08 15:55:55 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 355 ms / 2,000 ms |
コード長 | 1,718 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-14 20:11:31 |
合計ジャッジ時間 | 6,197 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
10,624 KB |
testcase_01 | AC | 31 ms
10,624 KB |
testcase_02 | AC | 47 ms
11,008 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 33 ms
10,752 KB |
testcase_06 | AC | 48 ms
10,880 KB |
testcase_07 | AC | 32 ms
10,624 KB |
testcase_08 | AC | 34 ms
10,752 KB |
testcase_09 | AC | 31 ms
10,624 KB |
testcase_10 | AC | 31 ms
10,752 KB |
testcase_11 | AC | 31 ms
10,880 KB |
testcase_12 | AC | 82 ms
11,008 KB |
testcase_13 | AC | 83 ms
10,880 KB |
testcase_14 | AC | 133 ms
11,136 KB |
testcase_15 | AC | 133 ms
11,136 KB |
testcase_16 | AC | 137 ms
11,008 KB |
testcase_17 | AC | 138 ms
11,008 KB |
testcase_18 | AC | 88 ms
11,136 KB |
testcase_19 | AC | 88 ms
11,008 KB |
testcase_20 | AC | 137 ms
11,264 KB |
testcase_21 | AC | 137 ms
11,008 KB |
testcase_22 | AC | 188 ms
11,212 KB |
testcase_23 | AC | 187 ms
11,084 KB |
testcase_24 | AC | 137 ms
10,880 KB |
testcase_25 | AC | 186 ms
11,212 KB |
testcase_26 | AC | 139 ms
11,080 KB |
testcase_27 | AC | 135 ms
11,088 KB |
testcase_28 | AC | 216 ms
11,212 KB |
testcase_29 | AC | 317 ms
11,516 KB |
testcase_30 | AC | 270 ms
11,516 KB |
testcase_31 | AC | 265 ms
11,520 KB |
testcase_32 | AC | 292 ms
11,648 KB |
testcase_33 | AC | 189 ms
11,244 KB |
testcase_34 | AC | 351 ms
11,388 KB |
testcase_35 | AC | 355 ms
11,392 KB |
ソースコード
def prob315(): MOD = 10 ** 9 + 7 def count(A, p, e, inclusive, MOD=MOD): prefix = 0 has3 = False f, s = 0, 0 mid = max(0, len(A) - 4 - e) for i in range(mid): # xrange d = ord(A[i]) - 0x30 f = (f * 10 + s) % MOD s = (s * 9) % MOD if has3: f = (f + d) % MOD else: s = (s + d - (d > 3)) % MOD f = (f + (d > 3)) % MOD prefix = (prefix + d) % 3 has3 |= d == 3 p3 = 3 * p curr = [0] * (4 * p) curr[0] = curr[1] = curr[2] = s * pow(3, MOD - 2, MOD) % MOD curr[p3] = f for i in range(mid, len(A)): next = [0] * (4 * p) d = ord(A[i]) - 0x30 for r in range(p3): if not curr[r]: continue for j in range(10): k = (p3 + (r * 10 + j) % p) if j == 3 else (r * 10 + j) % p3 next[k] = (next[k] + curr[r]) % MOD for r in range(p): if not curr[p3 + r]: continue for j in range(10): k = p3 + (r * 10 + j) % p next[k] = (next[k] + curr[p3 + r]) % MOD for j in range(d): k = p3 + (prefix * 10 + j) % p if (j == 3 or has3) else (prefix * 10 + j) % p3 next[k] = (next[k] + 1) % MOD prefix = (prefix * 10 + d) % p3 has3 |= d == 3 curr = next if inclusive: k = p3 + prefix % p if has3 else prefix curr[k] = (curr[k] + 1) % MOD ret = sum(c for i, c in enumerate(curr[:p3]) if i % 3 == 0 and i % p != 0) ret += sum(curr[p3+1:]) return ret % MOD import sys rl = sys.stdin.readline A, B, P = rl().split() P = int(P) e = 0 while P % 10 ** (e + 1) == 0: e += 1 a = count(A, P, e, False) b = count(B, P, e, True) print((b - a) % MOD) prob315()