結果

問題 No.260 世界のなんとか3
ユーザー maspymaspy
提出日時 2020-03-25 00:23:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,993 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,588 KB
最終ジャッジ日時 2023-08-30 09:06:42
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,128 KB
testcase_01 AC 19 ms
8,068 KB
testcase_02 AC 19 ms
8,164 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 61 ms
8,384 KB
testcase_06 AC 47 ms
8,180 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 78 ms
8,588 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 46 ms
8,036 KB
testcase_14 RE -
testcase_15 AC 58 ms
8,104 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 32 ms
8,164 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 19 ms
8,228 KB
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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)
0