結果

問題 No.129 お年玉(2)
ユーザー Yang33Yang33
提出日時 2018-05-01 23:23:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 5,000 ms
コード長 2,812 bytes
コンパイル時間 3,489 ms
コンパイル使用メモリ 163,452 KB
実行使用メモリ 392,548 KB
最終ジャッジ日時 2023-08-18 18:05:28
合計ジャッジ時間 8,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
89,652 KB
testcase_01 AC 218 ms
392,548 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 103 ms
251,444 KB
testcase_06 AC 153 ms
317,040 KB
testcase_07 AC 155 ms
351,732 KB
testcase_08 AC 115 ms
290,300 KB
testcase_09 AC 166 ms
337,392 KB
testcase_10 AC 167 ms
357,868 KB
testcase_11 AC 113 ms
284,252 KB
testcase_12 AC 145 ms
325,168 KB
testcase_13 AC 136 ms
331,264 KB
testcase_14 AC 140 ms
327,260 KB
testcase_15 AC 118 ms
296,476 KB
testcase_16 AC 153 ms
314,872 KB
testcase_17 AC 154 ms
347,696 KB
testcase_18 AC 138 ms
337,400 KB
testcase_19 AC 147 ms
349,676 KB
testcase_20 AC 144 ms
347,632 KB
testcase_21 AC 175 ms
388,600 KB
testcase_22 AC 112 ms
292,324 KB
testcase_23 AC 154 ms
364,272 KB
testcase_24 AC 148 ms
355,832 KB
testcase_25 AC 108 ms
284,408 KB
testcase_26 AC 108 ms
288,304 KB
testcase_27 AC 106 ms
284,188 KB
testcase_28 AC 174 ms
390,652 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 8 ms
32,300 KB
testcase_34 AC 6 ms
20,076 KB
testcase_35 AC 8 ms
30,264 KB
testcase_36 AC 8 ms
32,232 KB
testcase_37 AC 10 ms
36,532 KB
testcase_38 AC 38 ms
130,556 KB
testcase_39 AC 49 ms
161,308 KB
testcase_40 AC 102 ms
274,024 KB
testcase_41 AC 71 ms
212,476 KB
testcase_42 AC 40 ms
138,868 KB
testcase_43 AC 40 ms
136,756 KB
testcase_44 AC 173 ms
390,716 KB
testcase_45 AC 28 ms
101,944 KB
testcase_46 AC 53 ms
171,808 KB
testcase_47 AC 167 ms
384,504 KB
testcase_48 AC 114 ms
298,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000000;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/26  Problem: yukicoder 129  / Link: http://yukicoder.me/problems/no/129  ----- */
/* ------問題------

Yasuoは、予算がN円しかないが、親戚の子供M人にお年玉をあげたいと思っている。
お年玉の中に入れる種類は1000円紙幣だけにしたいと思っているが、なるべく平等でかつ最大の金額をあげたいと思っています。

今回は、前回のように配って予算が余った分も配り「当たり」とすることにした。

準備として、すべてのお年玉袋に、平等で最大な額の1000円紙幣を入れた後に、予算が余っているなら、「当たり」として、
1つの同じ袋には、1000円をいれるかいれないかとして、ランダムにそれぞれのお年玉袋に追加で振り分けることにした。

この時、誰がどのお年玉袋がもらえるかはわからないとして、
M人のそれぞれのもらえるお年玉の額の組み合わせは、何通りあるか求めてください。
1000円紙幣にできるなら余りを全て使うものとする。
答えが非常に大きくなるので1000000000=10^9(素数ではないことに注意)で割った余りを求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */
int  comb[10004][10004];
int calcomb(int M, int left) {
	int  i, j;
	for (i = 0; i <= M; i++) {
		for (j = 0; j <= i; j++) {
			if (j == 0 || j == i)
				comb[i][j] = 1;
			else
				comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j])%MOD;
		}
	}
	return comb[M][left];
}
LL ans = 0LL;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, M; cin >> N >> M;
	LL left = (N / 1000) % M;
	ans = calcomb(M, left);
	// leftをM人に配る(空を配りうる)
	cout << ans << "\n";

	return 0;
}
0