結果

問題 No.129 お年玉(2)
ユーザー asugen0402asugen0402
提出日時 2019-03-08 09:25:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 238 ms / 5,000 ms
コード長 2,367 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 30,344 KB
実行使用メモリ 390,932 KB
最終ジャッジ日時 2023-08-18 18:17:20
合計ジャッジ時間 7,306 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
88,140 KB
testcase_01 AC 238 ms
390,932 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 106 ms
249,788 KB
testcase_06 AC 158 ms
315,396 KB
testcase_07 AC 185 ms
350,216 KB
testcase_08 AC 141 ms
288,856 KB
testcase_09 AC 174 ms
335,960 KB
testcase_10 AC 191 ms
356,432 KB
testcase_11 AC 132 ms
282,688 KB
testcase_12 AC 165 ms
323,668 KB
testcase_13 AC 170 ms
329,696 KB
testcase_14 AC 165 ms
325,680 KB
testcase_15 AC 142 ms
294,840 KB
testcase_16 AC 158 ms
313,428 KB
testcase_17 AC 184 ms
346,060 KB
testcase_18 AC 175 ms
335,832 KB
testcase_19 AC 185 ms
348,128 KB
testcase_20 AC 180 ms
346,080 KB
testcase_21 AC 220 ms
387,004 KB
testcase_22 AC 137 ms
290,832 KB
testcase_23 AC 195 ms
362,580 KB
testcase_24 AC 193 ms
354,268 KB
testcase_25 AC 131 ms
282,556 KB
testcase_26 AC 135 ms
286,796 KB
testcase_27 AC 132 ms
282,588 KB
testcase_28 AC 220 ms
389,088 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 0 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 8 ms
30,804 KB
testcase_34 AC 4 ms
18,480 KB
testcase_35 AC 7 ms
28,612 KB
testcase_36 AC 7 ms
30,676 KB
testcase_37 AC 8 ms
34,776 KB
testcase_38 AC 41 ms
129,076 KB
testcase_39 AC 59 ms
159,828 KB
testcase_40 AC 127 ms
272,472 KB
testcase_41 AC 83 ms
210,996 KB
testcase_42 AC 45 ms
137,160 KB
testcase_43 AC 44 ms
135,248 KB
testcase_44 AC 222 ms
389,324 KB
testcase_45 AC 29 ms
100,312 KB
testcase_46 AC 60 ms
169,928 KB
testcase_47 AC 216 ms
382,936 KB
testcase_48 AC 143 ms
297,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MOD			1000000000								// 除数(10の9乗)
#define D_COMB_MAX		10005									// 最大人数

// 内部変数
static FILE *szpFpI;											// 入力
static int si2Comb[D_COMB_MAX][D_COMB_MAX];						// 組み合わせ表[n][k] = nCk

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// nCk(組み合わせ表[n][k])の作成 - パスカルの三角形
int
fMakeComb(
	int piRng					// <I> 範囲
)
{
	int i, j;

	for (i = 0; i <= piRng; ++i) {
		for (j = 0; j <= i; ++j) {
			if (j == 0 || j == i) {
				si2Comb[i][j] = 1;
			}
			else {
				si2Comb[i][j] = si2Comb[i - 1][j - 1] + si2Comb[i - 1][j];
				si2Comb[i][j] %= D_MOD;
			}
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1~
)
{
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 金額 - 取得
	long long llMoney;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &llMoney);

	// 人数 - 取得
	int liAll;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liAll);

	// nCk(組み合わせ表[n][k])の作成 - パスカルの三角形
	fMakeComb(liAll);

	// 残額
	llMoney %= liAll * 1000;

	// 当たり人数
	int liHit = (int)(llMoney / 1000);

	// 結果 - セット
	sprintf(lc1Out, "%d\n", si2Comb[liAll][liHit]);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}

0