結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | maspy |
提出日時 | 2020-05-05 19:22:04 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 455 ms / 2,000 ms |
コード長 | 1,644 bytes |
コンパイル時間 | 87 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 15,696 KB |
最終ジャッジ日時 | 2024-06-27 01:13:22 |
合計ジャッジ時間 | 9,308 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
10,752 KB |
testcase_01 | AC | 83 ms
10,752 KB |
testcase_02 | AC | 111 ms
10,752 KB |
testcase_03 | AC | 117 ms
10,880 KB |
testcase_04 | AC | 131 ms
10,624 KB |
testcase_05 | AC | 112 ms
10,752 KB |
testcase_06 | AC | 129 ms
10,752 KB |
testcase_07 | AC | 112 ms
10,624 KB |
testcase_08 | AC | 118 ms
10,752 KB |
testcase_09 | AC | 105 ms
10,624 KB |
testcase_10 | AC | 94 ms
10,624 KB |
testcase_11 | AC | 116 ms
10,752 KB |
testcase_12 | AC | 185 ms
12,544 KB |
testcase_13 | AC | 159 ms
12,416 KB |
testcase_14 | AC | 249 ms
13,336 KB |
testcase_15 | AC | 244 ms
13,336 KB |
testcase_16 | AC | 241 ms
13,336 KB |
testcase_17 | AC | 239 ms
13,336 KB |
testcase_18 | AC | 191 ms
12,416 KB |
testcase_19 | AC | 209 ms
12,544 KB |
testcase_20 | AC | 190 ms
12,416 KB |
testcase_21 | AC | 199 ms
12,416 KB |
testcase_22 | AC | 278 ms
13,332 KB |
testcase_23 | AC | 258 ms
13,336 KB |
testcase_24 | AC | 268 ms
13,204 KB |
testcase_25 | AC | 253 ms
13,460 KB |
testcase_26 | AC | 261 ms
13,204 KB |
testcase_27 | AC | 248 ms
13,340 KB |
testcase_28 | AC | 266 ms
13,204 KB |
testcase_29 | AC | 395 ms
15,688 KB |
testcase_30 | AC | 397 ms
15,564 KB |
testcase_31 | AC | 381 ms
15,564 KB |
testcase_32 | AC | 387 ms
15,696 KB |
testcase_33 | AC | 254 ms
14,336 KB |
testcase_34 | AC | 383 ms
15,568 KB |
testcase_35 | AC | 455 ms
15,688 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 A, B, P = readline().split() P = int(P) A = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in A] B = [0, 0, 0, 0, 0] + [int(x) - ord('0') for x in B] def solve(A, P, include=True): total = 0 no_3 = 0 cnt = (0, 1, 2, 3, 3, 4, 5, 6, 7, 8) full_use_3 = False MOD3 = 3 * MOD for x in A[:-6]: total = (10 * total + x) % MOD3 no_3 = (9 * no_3) % MOD if not full_use_3: no_3 += cnt[x] full_use_3 |= x == 3 n = no_3 * 3 no_3 = [n, n, n] x = A[-6] full_use_3 |= 3 in A[:-6] for d in range(x): if full_use_3 or d == 3: continue no_3[(total + d) % 3] += 1 total = (total * 10 + x) % MOD3 use_3 = (total - sum(no_3)) % MOD full_mod_3 = total % 3 U = 0 for x in A[-5:]: U = 10 * U + x ret = 0 for x in range(10**5): if x % P == 0: continue if '3' in str(x): ret += total else: ret += use_3 + no_3[(-x) % 3] for x in range(U + include): if x % P == 0: continue if '3' in str(x) or full_use_3: ret += 1 else: ret += (full_mod_3 + x) % 3 == 0 return ret def solve_naive(A, P, include): N = 0 for x in A: N = 10 * N + x ret = 0 for x in range(N + include): if x % P == 0: continue ret += '3' in str(x) or x % 3 == 0 return ret x = solve(B, P, True) - solve(A, P, False) print(x % MOD)