結果

問題 No.42 貯金箱の溜息
ユーザー antaanta
提出日時 2015-11-14 05:28:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 810 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 53,564 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 17:40:33
合計ジャッジ時間 1,190 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,352 KB
testcase_01 AC 23 ms
4,352 KB
testcase_02 AC 22 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
typedef long long ll;
using namespace std;

int main() {
	const int Mod = 1000000009;
	const int N = 6;
	const int xs[N] = {1, 5, 10, 50, 100, 500};
	const int Y = 500, X = Y * N;
	int dp[X + 1] = {};
	dp[0] = 1;
	rep(i, N) {
		int x = xs[i];
		for(int j = 0; j <= X - x; ++ j)
			(dp[j + x] += dp[j]) %= Mod;
	}
	int inv[N];
	inv[1] = 1;
	for(int i = 2; i < N; ++ i)
		inv[i] = (ll)inv[Mod % i] * (Mod - Mod / i) % Mod;
	int T;
	cin >> T;
	rep(ii, T) {
		ll M;
		cin >> M;
		ll ans = 0;
		rep(i, N) {
			ll prod = 1;
			rep(j, N) if(i != j)
				(prod *= (M / Y - j) % Mod * inv[abs(i - j)] * (i < j ? -1 : 1) % Mod) %= Mod;
			(ans += prod * dp[i * Y + M % Y]) %= Mod;
		}
		if(ans < 0) ans += Mod;
		cout << ans << endl;
	}
	return 0;
}
0