結果

問題 No.42 貯金箱の溜息
ユーザー maspymaspy
提出日時 2020-04-09 19:44:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 662 ms / 5,000 ms
コード長 855 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 31,104 KB
最終ジャッジ日時 2023-10-11 21:25:44
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 640 ms
30,468 KB
testcase_01 AC 662 ms
31,104 KB
testcase_02 AC 630 ms
30,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 9

F = np.zeros(5000, np.int64)
F[0] = 1
for x in [500, 100, 50, 10, 5, 1]:
    F[::x] = np.cumsum(F[::x]) % MOD

F.flags.writeable = False

comb = np.zeros((10, 10), np.int64)
comb[0, 0] = 1
for n in range(1, 10):
    comb[n] += comb[n - 1]
    comb[n, 1:] += comb[n - 1, :-1]


def f(N):
    q, r = divmod(N, 500)
    A = F[r: r + 500 * 7:500].copy()
    comb_q = [1] * 7
    for i in range(1, 7):
        comb_q[i] = comb_q[i - 1] * (q + 1 - i) * pow(i, MOD - 2, MOD) % MOD
    ret = 0
    for i in range(7):
        ret += A[i] * comb_q[i] % MOD
        A -= A[i] * comb[:7, i] % MOD
    return ret % MOD


T = int(readline())
nums = map(int, read().split())
print('\n'.join(map(str, map(f, nums))))
0