結果

問題 No.260 世界のなんとか3
ユーザー shiccocsanshiccocsan
提出日時 2017-01-03 16:19:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 2,065 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 74,100 KB
最終ジャッジ日時 2023-08-22 10:22:48
合計ジャッジ時間 5,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 WA -
testcase_02 WA -
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def get_multi_dimensional_list(v, *args):
    """
    :param v:初期値
    :param args:各次元のサイズ
    :return:多次元のリスト
    """
    import copy
    res = v
    if args:
        if isinstance(v, list):
            res = [copy.deepcopy(v) for i in range(args[-1])]
        else:
            res = [v] * args[-1]

        if len(args) > 1:
            return get_multi_dimensional_list(res, *args[:-1])
    return res


def solve():
    A, B = input().split()
    L = max(len(A), len(B))

    A = (("0" * (L + 1)) + A)[-L - 1:]
    B = (("0" * (L + 1)) + B)[-L - 1:]

    dp = get_multi_dimensional_list(0, L + 2, 2, 2, 2, 3, 8)
    print(dp)

    dp[0][0][0][0][0][0] = 1
    for i in range(L + 1):  # 桁
        for j in range(2):  # A
            for k in range(2):  # B
                for l in range(2):  # 3がつくか
                    for m in range(3):  # 3の余り
                        for n in range(8):  # 8の余り
                            a_i = int(A[i])
                            b_i = int(B[i])
                            lim_l = 0 if j else a_i
                            lim_r = 9 if k else b_i
                            if lim_l > lim_r:
                                continue

                            for number in range(lim_l, lim_r + 1):
                                new_j = 1 if j or number > lim_l else 0
                                new_k = 1 if k or number < lim_r else 0
                                new_l = 1 if l or number == 3 else 0
                                new_m = (m * 10 + number) % 3
                                new_n = (n * 10 + number) % 8
                                dp[i + 1][new_j][new_k][new_l][new_m][new_n] += dp[i][j][k][l][m][n] % (10e9 + 7)

    res = 0
    # 3がつく
    for i in range(2):
        for j in range(2):
            for m in range(3):
                res += sum(dp[L + 1][i][j][1][m][1:]) % (10e9 + 7)
            # 3の倍数
            res += sum(dp[L + 1][i][j][0][0][1:]) % (10e9 + 7)
    print(int(res % (10e9 + 7)))

solve()
0