結果

問題 No.634 硬貨の枚数1
ユーザー asugen0402asugen0402
提出日時 2019-04-19 09:17:08
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 3,904 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 32,520 KB
実行使用メモリ 76,400 KB
最終ジャッジ日時 2023-10-23 17:23:52
合計ジャッジ時間 7,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,368 KB
testcase_01 AC 2 ms
5,984 KB
testcase_02 AC 6 ms
6,044 KB
testcase_03 AC 3 ms
6,012 KB
testcase_04 AC 3 ms
6,008 KB
testcase_05 AC 2 ms
5,988 KB
testcase_06 AC 3 ms
6,016 KB
testcase_07 AC 3 ms
6,000 KB
testcase_08 AC 2 ms
5,992 KB
testcase_09 AC 3 ms
6,020 KB
testcase_10 AC 3 ms
6,012 KB
testcase_11 AC 2 ms
5,996 KB
testcase_12 AC 4 ms
6,012 KB
testcase_13 AC 2 ms
5,992 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// 内部定数
#define D_VAL_MAX		10000005								// 最大値
#define D_STACK_MAX		D_VAL_MAX								// 最大スタック数

// 内部変数
static FILE *szpFpI;											// 入力
static int siPay;												// 支払い額
static int si1Coin[D_VAL_MAX];									// コイン
static int siCCnt;												// コイン数
static int si1UCnt[D_VAL_MAX];									// 使用コイン数[支払い額]
static int si1Stack[D_STACK_MAX];								// スタック
static int siSCnt;												// スタック数
static int siSSNo;												// スタック位置 - セット
static int siSGNo;												// スタック位置 - 取得

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

// 出力
int
fOut(
	char *pcpLine				// <I> 1行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// スタック - セット
int
fStackSet(
	int piVal					// <I> 支払い額
	, int piCoin				// <I> コイン数
)
{
	// 支払い額 - チェック
	if (piVal > siPay) {
		return 0;
	}

	// 使用コイン数 - チェック
	if (si1UCnt[piVal] <= piCoin) {
		return 0;
	}
	si1UCnt[piVal] = piCoin;

	// セット
	si1Stack[siSSNo] = piVal;

	// スタック数
	siSCnt++;

	// スタック位置 - セット
	if (siSSNo < D_STACK_MAX - 1) {
		siSSNo++;
	}
	else {
		siSSNo = 0;
	}

	return 0;
}

// スタック - 取得
int
fStackGet(
)
{
	// スタック数
	if (siSCnt < 1) {
		return -1;
	}
	siSCnt--;

	// 取得値
	int liRet = si1Stack[siSGNo];

	// スタック位置 - 取得
	if (siSGNo < D_STACK_MAX - 1) {
		siSGNo++;
	}
	else {
		siSGNo = 0;
	}

	return liRet;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// 支払い額 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siPay);

	// コイン - セット
	for (siCCnt = 0; ; siCCnt++) {
		si1Coin[siCCnt] = (siCCnt + 1) * (siCCnt + 2) / 2;
		if (si1Coin[siCCnt] > siPay) {
			break;
		}
	}

	// 使用コイン数 - 初期化
	si1UCnt[0] = 1;
	for (i = 1; i <= siPay; i++) {
		si1UCnt[i] = i;
	}

	// スタック - 初期値
	fStackSet(0, 0);

	// 使用コイン数 - セット
	int liCCnt;
	for (liCCnt = 1; ; liCCnt++) {

		// スタック数
		int liSCnt = siSCnt;
		if (liSCnt < 1) {
			break;
		}

		// スタック数でループ
		for (i = 0; i < liSCnt; i++) {
			int liVal = fStackGet();

			// コイン使用
			for (j = 0; j < siCCnt; j++) {
				fStackSet(liVal + si1Coin[j], liCCnt);
			}
		}
	}

	return si1UCnt[siPay];
}

// 1回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	siSCnt = 0;													// スタック数
	siSSNo = 0;													// スタック位置 - セット
	siSGNo = 0;													// スタック位置 - 取得

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

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOut(lc1Buf);

	// 残データ有無
#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", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

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

	return 0;
}

0