結果
問題 |
No.260 世界のなんとか3
|
ユーザー |
![]() |
提出日時 | 2020-03-25 00:23:28 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,993 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2025-01-01 19:02:05 |
合計ジャッジ時間 | 2,764 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 RE * 20 |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A, B = map(int, read().split()) MOD = 10**9 + 7 def f(N): """0以上N以下で数える""" N = tuple(map(int, '000' + str(N))) dp0 = [1, 0, 0] # 3のついていない数、N以下 dp1 = [0, 0, 0] # 3のついていない数、N-1以下 full = 0 for n in N[:-3]: full *= 10 full += n full %= MOD newdp0 = [0, 0, 0] newdp1 = [0, 0, 0] for i in range(10): if i == 3: continue if n >= i: for d in range(3): newdp0[(i + d) % 3] += dp0[d] else: for d in range(3): newdp0[(i + d) % 3] += dp1[d] if n >= i + 1: for d in range(3): newdp1[(i + d) % 3] += dp0[d] else: for d in range(3): newdp1[(i + d) % 3] += dp1[d] dp0 = [x % MOD for x in newdp0] dp1 = [x % MOD for x in newdp1] n = int(''.join(map(str, N[-3:]))) full8 = full * 125 full8 += n // 8 + 1 full *= 1000 full += n + 1 no_aho_no8 = 0 for i in range(1000): if i % 8 == 0: continue if str(i).count('3'): continue if i <= n: for j in range(3): if (i + j) % 3 != 0: x = dp0[j] no_aho_no8 += x if i > n: for j in range(3): if (i + j) % 3 != 0: x = dp1[j] no_aho_no8 += x return (full - full8 - no_aho_no8) % MOD def f_naive(N): N = int(''.join(map(str, N))) ret = 0 for i in range(N + 1): if i % 3 == 0 or str(i).count('3'): if i % 8 != 0: ret += 1 return ret answer = f(B) - f(A - 1) answer %= MOD print(answer)