結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー asugen0402asugen0402
提出日時 2019-01-18 09:57:36
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,144 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 30,320 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-19 03:58:37
合計ジャッジ時間 2,877 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 0 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 0 ms
4,380 KB
testcase_33 AC 0 ms
4,380 KB
testcase_34 AC 0 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 WA -
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 0 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 0 ms
4,380 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// 内部定数
#define D_WEEK_CNT		7										// 1週間
#define D_DAY_CNT		(D_WEEK_CNT * 2)						// 日数
#define D_CAL_HOLIDAY	'o'										// カレンダー - 休日

// 内部変数
static FILE *szpFpI;											// 入力
static int siSCnt;												// 有給数
static char sc1Cal[D_DAY_CNT + 5];								// カレンダー
static int siMax;												// 最大連休

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

// 最大連休 - 更新
int
fUpMax(
	char *pcpCal				// <I> カレンダー
	, int piSCnt				// <I> 残有給数
)
{
	int i;

	// 連休 - 取得
	int liLen = 0;
	for (i = 0; i <= D_DAY_CNT; i++) {
		if (pcpCal[i] == D_CAL_HOLIDAY) {		// 休日
			liLen++;
		}
		else {									// 平日
			liLen += piSCnt;

			// 最大連休 - 更新
			if (siMax < liLen) {
				siMax = liLen;
			}

			liLen = 0;
		}
	}

	return 0;
}

// 有給 - セット
int
fSetSalary(
	char *pcpCal				// <I> カレンダー
	, int piDay					// <I> 対象日 0~
	, int piSCnt				// <I> 有給数
)
{
	// 終了チェック
	if (piDay == D_DAY_CNT) {
		fUpMax(pcpCal, piSCnt);							// 最大連休 - 更新
		return 0;
	}

	// 翌日へ
	fSetSalary(pcpCal, piDay + 1, piSCnt);

	// カレンダーチェック
	if (pcpCal[piDay] == D_CAL_HOLIDAY) {			// 休日
		return 0;
	}

	// 有給有無
	if (piSCnt < 1) {								// なし
		return 0;
	}

	// 有給使用
	char lc1Cal[D_DAY_CNT + 5];
	memcpy(lc1Cal, pcpCal, sizeof(lc1Cal));
	lc1Cal[piDay] = D_CAL_HOLIDAY;
	fSetSalary(lc1Cal, piDay + 1, piSCnt - 1);		// 翌日へ

	return 0;
}

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

	// データ - 初期化
	siMax = 0;													// 最大連休

	// 入力 - セット
#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

	// 有給数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siSCnt);

	// カレンダー - 取得
	fgets(sc1Cal, sizeof(sc1Cal), szpFpI);
	fgets(&sc1Cal[D_WEEK_CNT], sizeof(sc1Cal) - D_WEEK_CNT, szpFpI);

	// 有給 - セット
	fSetSalary(sc1Cal, 0, siSCnt);

	// 結果 - セット
	sprintf(lc1Out, "%d\n", siMax);

	// 結果 - 表示
#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