結果
| 問題 |
No.42 貯金箱の溜息
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2015-11-14 05:28:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 5,000 ms |
| コード長 | 810 bytes |
| コンパイル時間 | 424 ms |
| コンパイル使用メモリ | 56,352 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-09-13 16:41:00 |
| 合計ジャッジ時間 | 1,079 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
#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;
}
anta