結果

問題 No.42 貯金箱の溜息
ユーザー maspymaspy
提出日時 2020-04-09 20:15:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 852 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 32,848 KB
最終ジャッジ日時 2023-10-11 21:26:07
合計ジャッジ時間 1,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
32,288 KB
testcase_01 AC 150 ms
32,732 KB
testcase_02 AC 150 ms
32,848 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(3000, np.int64)
F[0] = 1
for x in [500, 100, 50, 10, 5, 1]:
    F[::x] = np.cumsum(F[::x]) % MOD
F = F.reshape(6, 500).T

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

for i in range(6):
    F[:, i + 1:] -= F[:, i][:, None] * comb[i + 1:, i]
    F %= MOD

T = int(readline())
nums = np.array(read().split(), np.int64)

x, r = np.divmod(nums, 500)
x %= MOD
comb_x = np.empty((T, 6), np.int64)
comb_x[:, 0] = 1
for i in range(1, 6):
    comb_x[:, i] = comb_x[:, i - 1] * (x + 1 - i) % MOD * pow(i, MOD - 2, MOD) % MOD
answer = (F[r] * comb_x).sum(axis=1) % MOD
print('\n'.join(answer.astype(str)))
0