結果

問題 No.260 世界のなんとか3
ユーザー maspymaspy
提出日時 2023-06-11 23:45:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 2,027 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 8,668 KB
最終ジャッジ日時 2023-09-01 03:09:46
合計ジャッジ時間 5,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,120 KB
testcase_01 AC 19 ms
8,112 KB
testcase_02 AC 17 ms
8,036 KB
testcase_03 AC 250 ms
8,628 KB
testcase_04 AC 256 ms
8,632 KB
testcase_05 AC 61 ms
8,548 KB
testcase_06 AC 46 ms
8,496 KB
testcase_07 AC 172 ms
8,644 KB
testcase_08 AC 128 ms
8,524 KB
testcase_09 AC 78 ms
8,432 KB
testcase_10 AC 194 ms
8,516 KB
testcase_11 AC 183 ms
8,580 KB
testcase_12 AC 117 ms
8,476 KB
testcase_13 AC 45 ms
8,076 KB
testcase_14 AC 169 ms
8,668 KB
testcase_15 AC 55 ms
8,124 KB
testcase_16 AC 150 ms
8,568 KB
testcase_17 AC 121 ms
8,408 KB
testcase_18 AC 119 ms
8,464 KB
testcase_19 AC 151 ms
8,628 KB
testcase_20 AC 108 ms
8,116 KB
testcase_21 AC 101 ms
8,544 KB
testcase_22 AC 170 ms
8,440 KB
testcase_23 AC 32 ms
8,172 KB
testcase_24 AC 135 ms
8,396 KB
testcase_25 AC 133 ms
8,536 KB
testcase_26 AC 133 ms
8,536 KB
testcase_27 AC 19 ms
8,264 KB
testcase_28 AC 248 ms
8,668 KB
testcase_29 AC 250 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
sys.set_int_max_str_digits(10**5)
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)
0