結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー ansainansain
提出日時 2021-03-30 20:23:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 3,000 ms
コード長 3,028 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 78,340 KB
最終ジャッジ日時 2023-08-20 17:10:14
合計ジャッジ時間 6,352 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,464 KB
testcase_01 AC 76 ms
71,460 KB
testcase_02 AC 103 ms
76,320 KB
testcase_03 AC 75 ms
71,552 KB
testcase_04 AC 74 ms
71,532 KB
testcase_05 AC 77 ms
71,376 KB
testcase_06 AC 76 ms
71,328 KB
testcase_07 AC 75 ms
71,296 KB
testcase_08 AC 80 ms
71,300 KB
testcase_09 AC 75 ms
71,180 KB
testcase_10 AC 77 ms
71,144 KB
testcase_11 AC 78 ms
71,300 KB
testcase_12 AC 85 ms
76,452 KB
testcase_13 AC 85 ms
76,208 KB
testcase_14 AC 90 ms
76,572 KB
testcase_15 AC 92 ms
76,500 KB
testcase_16 AC 93 ms
76,616 KB
testcase_17 AC 93 ms
76,628 KB
testcase_18 AC 100 ms
76,488 KB
testcase_19 AC 101 ms
76,536 KB
testcase_20 AC 101 ms
76,820 KB
testcase_21 AC 101 ms
76,524 KB
testcase_22 AC 100 ms
76,620 KB
testcase_23 AC 101 ms
76,488 KB
testcase_24 AC 100 ms
76,312 KB
testcase_25 AC 102 ms
76,620 KB
testcase_26 AC 102 ms
76,540 KB
testcase_27 AC 101 ms
76,620 KB
testcase_28 AC 103 ms
76,660 KB
testcase_29 AC 103 ms
76,696 KB
testcase_30 AC 143 ms
77,896 KB
testcase_31 AC 133 ms
77,692 KB
testcase_32 AC 157 ms
78,204 KB
testcase_33 AC 156 ms
77,912 KB
testcase_34 AC 188 ms
78,340 KB
testcase_35 AC 186 ms
78,084 KB
testcase_36 AC 186 ms
78,200 KB
testcase_37 AC 188 ms
78,100 KB
testcase_38 AC 169 ms
78,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    # modの値は予め準備しておく
    mod = 10**9+7
    mod2 = 998244353

    # Nを桁ごとの数字のリストとして受け取る
    n = list(map(int, list(input())))

    # あればその他の入力を受け取る

    # dp[i][j]=今まで見てきた数字未満の数で、桁掛に含まれる2の素因数がi個,5の素因数がj個(ただし最大2)の数
    # nの最上位桁の値で初期化(最上位桁が7なら、1~6までの数字の数え上げ結果になるように初期化する)
    dp = [[0]*3 for i in range(3)]
    for i in range(1, n[0]):
        dp[int(i % 2 == 0)+int(i % 4 == 0)][i % 5 == 0] += 1

    # n_info=今までの見てきた数字の桁掛の2,5の素因数と、桁に0が含まれないか
    # nの最上位桁の値で初期化
    n_info = [int(n[0] % 2 == 0)+int(n[0] % 4 == 0), int(n[0] % 5 == 0), True]

    # nを上位2桁目から見ていく。
    for nn in n[1:]:
        """
        具体例として今まで見てきた数字が37とする。
        dpには、1から36までの数え上げ結果が入っている。
        n_infoには37に関する情報が入っている。
        ここに新たに次の桁としてnn=6を見るとするとき。
        newdpに、1から375までの数え上げ結果を入れたい。
        """
        # newdpを入れる配列を作る。
        newdp = [[0]*3 for i in range(3)]

        # 1から36までの数え上げ結果から、10から369までの数え上げ結果を計算する。
        for i in range(1, 10):
            for n2 in range(3):
                for n5 in range(3):
                    nn2 = min(n2+int(i%2 == 0)+int(i%4 == 0), 2)
                    nn5 = min(n5+int(i % 5 == 0), 2)
                    newdp[nn2][nn5] += dp[n2][n5]
                    newdp[nn2][nn5] %= mod

        # 370から375の数え上げ結果を、n_infoから計算する。
        n2, n5, n0 = n_info
        if n0:
            for i in range(1, nn):
                nn2 = min(n2+int(i%2 == 0)+int(i%4 == 0),2)
                nn5 = min(n5+int(i%5 == 0),2)
                newdp[nn2][nn5] += 1

        # 1から9の数え上げ結果を計算する。
        for i in range(1, 10):
            newdp[int(i%2 == 0)+int(i%4 == 0)][i%5 == 0] += 1

        # dpをnewdpに更新する
        dp = newdp[:][:]

        # n_infoを376に関する情報に更新する。
        n_info[0] += int(nn%2 == 0)+int(nn%4 == 0)
        n_info[1] += nn%5 == 0
        if nn == 0:
            n_info[2] = False

    # n自身が数え上げ結果に入っていないので加える。nの桁を最後まで見たので、n_infoはn自身に関する情報が入っているはず。
    n2, n5,n0 = n_info
    if n0:
        nn2 = min(n2, 2)
        nn5 = min(n5, 2)
        dp[nn2][nn5] += 1

    # 0を除外するなら除外する

    # 答えを出力
    print(dp[2][2] % mod)


if __name__ == '__main__':
    main()
0