結果

問題 No.129 お年玉(2)
ユーザー Yang33Yang33
提出日時 2018-05-01 23:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 5,000 ms
コード長 2,824 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 165,960 KB
実行使用メモリ 432,896 KB
最終ジャッジ日時 2024-05-05 23:42:38
合計ジャッジ時間 10,464 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
31,488 KB
testcase_01 AC 351 ms
432,896 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 144 ms
187,904 KB
testcase_06 AC 219 ms
288,768 KB
testcase_07 AC 282 ms
350,208 KB
testcase_08 AC 184 ms
243,840 KB
testcase_09 AC 244 ms
323,584 KB
testcase_10 AC 280 ms
362,112 KB
testcase_11 AC 177 ms
234,240 KB
testcase_12 AC 226 ms
301,440 KB
testcase_13 AC 256 ms
314,624 KB
testcase_14 AC 232 ms
304,384 KB
testcase_15 AC 194 ms
253,184 KB
testcase_16 AC 217 ms
286,080 KB
testcase_17 AC 274 ms
343,680 KB
testcase_18 AC 257 ms
324,864 KB
testcase_19 AC 270 ms
345,472 KB
testcase_20 AC 262 ms
342,912 KB
testcase_21 AC 331 ms
423,552 KB
testcase_22 AC 196 ms
246,400 KB
testcase_23 AC 295 ms
372,736 KB
testcase_24 AC 278 ms
358,656 KB
testcase_25 AC 178 ms
235,776 KB
testcase_26 AC 186 ms
241,152 KB
testcase_27 AC 203 ms
234,368 KB
testcase_28 AC 327 ms
427,520 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 6 ms
8,704 KB
testcase_34 AC 4 ms
5,760 KB
testcase_35 AC 5 ms
8,320 KB
testcase_36 AC 6 ms
8,704 KB
testcase_37 AC 6 ms
9,984 KB
testcase_38 AC 41 ms
57,856 KB
testcase_39 AC 64 ms
84,096 KB
testcase_40 AC 170 ms
219,904 KB
testcase_41 AC 105 ms
138,624 KB
testcase_42 AC 48 ms
64,768 KB
testcase_43 AC 46 ms
63,744 KB
testcase_44 AC 340 ms
429,568 KB
testcase_45 AC 29 ms
38,912 KB
testcase_46 AC 71 ms
93,056 KB
testcase_47 AC 333 ms
416,128 KB
testcase_48 AC 198 ms
256,640 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(素数ではないことに注意)で割った余りを求めてください。

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



----解説ここまで---- */
long long  comb[10004][10004];
long long 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