Submission #3601871


Source Code Expand

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

// 内部定数
#define D_LINE_MAX		4000									// 最大直線長
#define D_LINE_INI		0										// 直線 - 初期
#define D_LINE_HURDLE	1										// 直線 - ハードル
#define D_LINE_OK		2										// 直線 - ジャンプ可能

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Line[D_LINE_MAX + 5];								// 直線
static int siJunmp;												// ジャンプ距離
static int siHFirst;											// ハードル - 最初
static int siHLast;												// ハードル - 最後

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

// ハードル - 取得
int
fGetHurdle(
)
{
	char lc1Buf[1024];

	int liVal;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liVal);
	liVal *= 2;
	si1Line[liVal] = D_LINE_HURDLE;

	return liVal;
}

// ハードル - 存在チェック
int
fExistHurdle(
	int piSNo					// <I> 開始
	, int piENo					// <I> 終了
)
{
	int i;

	for (i = piSNo; i <= piENo; i++) {
		if (si1Line[i] == D_LINE_HURDLE) {
			return 1;
		}
	}

	return 0;
}

// 判定
int
fJudge(
)
{
	int i, j, liRet;

	// 初期設定
	for (i = 0; i < siHFirst; i++) {
		si1Line[i] = D_LINE_OK;
	}

	// 順にチェック
	for (i = 0; i < siHLast; i++) {
		if (si1Line[i] != D_LINE_OK) {							// ジャンプ可能以外
			continue;
		}

		// 走行位置
		int liSNo = i + siJunmp;
		int liENo = liSNo + siJunmp;

		// ハードル - 存在チェック
		liRet = fExistHurdle(liSNo, liENo);
		if (liRet != 0) {										// あり
			continue;
		}

		// ゴールチェック
		if (liENo > siHLast) {
			return 0;
		}

		// ジャンプ可能
		for (j = liENo; j < siHLast; j++) {
			if (si1Line[j] == D_LINE_INI) {							// 初期
				si1Line[j] = D_LINE_OK;
			}
			else if (si1Line[j] == D_LINE_HURDLE) {					// ハードル
				break;
			}
		}
	}

	return -1;
}

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

	// データ - 初期化
	memset(si1Line, D_LINE_INI, sizeof(si1Line));				// 直線

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

	// ハードル数・ジャンプ距離 - 取得
	int liHCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &liHCnt, &siJunmp);
	if (siJunmp > 2000) {
		return 0;
	}
	siJunmp *= 2;

	// ハードル - 最初
	siHFirst = fGetHurdle();

	// ハードル - 最初~最後
	for (i = 1; i < liHCnt - 1; i++) {
		fGetHurdle();
	}

	// ハードル - 最後
	if (liHCnt > 1) {
		siHLast = fGetHurdle();
	}
	else {
		siHLast = siHFirst;
	}

	// 判定
	int liRet = fJudge();

	// 結果 - セット
	if (liRet == 0) {
		sprintf(lc1Out, "YES\n");
	}
	else {
		sprintf(lc1Out, "NO\n");
	}

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

Submission Info

Submission Time
Task C - ハードル走
User asugen0402
Language C (GCC 5.4.1)
Score 0
Code Size 3909 Byte
Status RE
Exec Time 316 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘fGetHurdle’:
./Main.c:35:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
  ^
./Main.c: In function ‘fMain’:
./Main.c:133:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
  ^

Judge Result

Set Name Sample Small All
Score / Max Score 0 / 0 0 / 400 0 / 100
Status
AC × 6
WA × 1
AC × 54
RE × 8
AC × 54
WA × 45
RE × 10
Set Name Test Cases
Sample 00_sample_06, 00_sample_part_00, 00_sample_part_01, 00_sample_part_02, 00_sample_part_03, 00_sample_part_04, 00_sample_part_05
Small 00_sample_part_00, 00_sample_part_01, 00_sample_part_02, 00_sample_part_03, 00_sample_part_04, 00_sample_part_05, 50_random_NLsmall_part_00, 50_random_NLsmall_part_01, 50_random_NLsmall_part_02, 50_random_NLsmall_part_03, 50_random_NLsmall_part_04, 50_random_NLsmall_part_05, 50_random_NLsmall_part_06, 50_random_NLsmall_part_07, 50_random_NLsmall_part_08, 50_random_NLsmall_part_09, 50_random_XiNsmall_narrow_part_00, 50_random_XiNsmall_narrow_part_01, 50_random_XiNsmall_narrow_part_02, 50_random_XiNsmall_narrow_part_03, 50_random_XiNsmall_narrow_part_04, 50_random_XiNsmall_narrow_part_05, 50_random_XiNsmall_narrow_part_06, 50_random_XiNsmall_narrow_part_07, 50_random_XiNsmall_narrow_part_08, 50_random_XiNsmall_narrow_part_09, 50_random_XiNsmall_part_00, 50_random_XiNsmall_part_01, 50_random_XiNsmall_part_02, 50_random_XiNsmall_part_03, 50_random_XiNsmall_part_04, 50_random_XiNsmall_part_05, 50_random_XiNsmall_part_06, 50_random_XiNsmall_part_07, 50_random_XiNsmall_part_08, 50_random_XiNsmall_part_09, 50_random_x1small_part_00, 50_random_x1small_part_01, 50_random_x1small_part_02, 50_random_x1small_part_03, 50_random_x1small_part_04, 50_random_x1small_part_05, 50_random_x1small_part_06, 50_random_x1small_part_07, 50_random_x1small_part_08, 50_random_x1small_part_09, 80_hand_part_01, 80_hand_part_02, 80_hand_part_03, 80_hand_part_04, 80_hand_part_05, 80_hand_part_06, 80_hand_part_07, 80_hand_part_08, 80_hand_part_11, 80_hand_part_12, 98_challenge_part_00, 98_challenge_part_01, 98_challenge_part_02, 98_challenge_part_03, 98_challenge_part_04, 98_challenge_part_05
All 00_sample_06, 00_sample_part_00, 00_sample_part_01, 00_sample_part_02, 00_sample_part_03, 00_sample_part_04, 00_sample_part_05, 50_random_NLsmall_part_00, 50_random_NLsmall_part_01, 50_random_NLsmall_part_02, 50_random_NLsmall_part_03, 50_random_NLsmall_part_04, 50_random_NLsmall_part_05, 50_random_NLsmall_part_06, 50_random_NLsmall_part_07, 50_random_NLsmall_part_08, 50_random_NLsmall_part_09, 50_random_XiNsmall_00, 50_random_XiNsmall_01, 50_random_XiNsmall_02, 50_random_XiNsmall_03, 50_random_XiNsmall_04, 50_random_XiNsmall_05, 50_random_XiNsmall_06, 50_random_XiNsmall_07, 50_random_XiNsmall_08, 50_random_XiNsmall_09, 50_random_XiNsmall_narrow_part_00, 50_random_XiNsmall_narrow_part_01, 50_random_XiNsmall_narrow_part_02, 50_random_XiNsmall_narrow_part_03, 50_random_XiNsmall_narrow_part_04, 50_random_XiNsmall_narrow_part_05, 50_random_XiNsmall_narrow_part_06, 50_random_XiNsmall_narrow_part_07, 50_random_XiNsmall_narrow_part_08, 50_random_XiNsmall_narrow_part_09, 50_random_XiNsmall_part_00, 50_random_XiNsmall_part_01, 50_random_XiNsmall_part_02, 50_random_XiNsmall_part_03, 50_random_XiNsmall_part_04, 50_random_XiNsmall_part_05, 50_random_XiNsmall_part_06, 50_random_XiNsmall_part_07, 50_random_XiNsmall_part_08, 50_random_XiNsmall_part_09, 50_random_Xilarge_00, 50_random_Xilarge_01, 50_random_Xilarge_02, 50_random_Xilarge_03, 50_random_Xilarge_04, 50_random_Xilarge_05, 50_random_Xilarge_06, 50_random_Xilarge_07, 50_random_Xilarge_08, 50_random_Xilarge_09, 50_random_Xilarge_narrow_00, 50_random_Xilarge_narrow_01, 50_random_Xilarge_narrow_02, 50_random_Xilarge_narrow_03, 50_random_Xilarge_narrow_04, 50_random_Xilarge_narrow_05, 50_random_Xilarge_narrow_06, 50_random_Xilarge_narrow_07, 50_random_Xilarge_narrow_08, 50_random_Xilarge_narrow_09, 50_random_x0small_00, 50_random_x0small_01, 50_random_x0small_02, 50_random_x0small_03, 50_random_x0small_04, 50_random_x0small_05, 50_random_x0small_06, 50_random_x0small_07, 50_random_x0small_08, 50_random_x0small_09, 50_random_x1small_part_00, 50_random_x1small_part_01, 50_random_x1small_part_02, 50_random_x1small_part_03, 50_random_x1small_part_04, 50_random_x1small_part_05, 50_random_x1small_part_06, 50_random_x1small_part_07, 50_random_x1small_part_08, 50_random_x1small_part_09, 80_hand_09, 80_hand_10, 80_hand_part_01, 80_hand_part_02, 80_hand_part_03, 80_hand_part_04, 80_hand_part_05, 80_hand_part_06, 80_hand_part_07, 80_hand_part_08, 80_hand_part_11, 80_hand_part_12, 90_max_no_00, 90_max_no_01, 90_max_yes_00, 90_max_yes_01, 98_challenge_part_00, 98_challenge_part_01, 98_challenge_part_02, 98_challenge_part_03, 98_challenge_part_04, 98_challenge_part_05
Case Name Status Exec Time Memory
00_sample_06 WA 1 ms 128 KB
00_sample_part_00 AC 1 ms 128 KB
00_sample_part_01 AC 1 ms 128 KB
00_sample_part_02 AC 1 ms 128 KB
00_sample_part_03 AC 1 ms 128 KB
00_sample_part_04 AC 1 ms 128 KB
00_sample_part_05 AC 1 ms 128 KB
50_random_NLsmall_part_00 AC 1 ms 128 KB
50_random_NLsmall_part_01 AC 1 ms 128 KB
50_random_NLsmall_part_02 AC 1 ms 128 KB
50_random_NLsmall_part_03 AC 1 ms 128 KB
50_random_NLsmall_part_04 AC 1 ms 128 KB
50_random_NLsmall_part_05 AC 1 ms 128 KB
50_random_NLsmall_part_06 RE 316 ms 128 KB
50_random_NLsmall_part_07 RE 98 ms 128 KB
50_random_NLsmall_part_08 RE 100 ms 128 KB
50_random_NLsmall_part_09 AC 1 ms 128 KB
50_random_XiNsmall_00 WA 1 ms 128 KB
50_random_XiNsmall_01 WA 1 ms 128 KB
50_random_XiNsmall_02 WA 1 ms 128 KB
50_random_XiNsmall_03 WA 1 ms 128 KB
50_random_XiNsmall_04 WA 1 ms 128 KB
50_random_XiNsmall_05 WA 1 ms 128 KB
50_random_XiNsmall_06 WA 1 ms 128 KB
50_random_XiNsmall_07 WA 1 ms 128 KB
50_random_XiNsmall_08 WA 1 ms 128 KB
50_random_XiNsmall_09 WA 1 ms 128 KB
50_random_XiNsmall_narrow_part_00 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_01 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_02 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_03 RE 98 ms 128 KB
50_random_XiNsmall_narrow_part_04 RE 97 ms 128 KB
50_random_XiNsmall_narrow_part_05 RE 97 ms 128 KB
50_random_XiNsmall_narrow_part_06 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_07 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_08 AC 1 ms 128 KB
50_random_XiNsmall_narrow_part_09 RE 98 ms 128 KB
50_random_XiNsmall_part_00 AC 1 ms 128 KB
50_random_XiNsmall_part_01 AC 1 ms 128 KB
50_random_XiNsmall_part_02 AC 1 ms 128 KB
50_random_XiNsmall_part_03 AC 1 ms 128 KB
50_random_XiNsmall_part_04 AC 1 ms 128 KB
50_random_XiNsmall_part_05 AC 1 ms 128 KB
50_random_XiNsmall_part_06 AC 1 ms 128 KB
50_random_XiNsmall_part_07 AC 1 ms 128 KB
50_random_XiNsmall_part_08 AC 1 ms 128 KB
50_random_XiNsmall_part_09 AC 1 ms 128 KB
50_random_Xilarge_00 WA 0 ms 128 KB
50_random_Xilarge_01 WA 1 ms 128 KB
50_random_Xilarge_02 WA 1 ms 128 KB
50_random_Xilarge_03 WA 1 ms 128 KB
50_random_Xilarge_04 WA 1 ms 128 KB
50_random_Xilarge_05 WA 1 ms 128 KB
50_random_Xilarge_06 WA 1 ms 128 KB
50_random_Xilarge_07 WA 1 ms 128 KB
50_random_Xilarge_08 WA 1 ms 128 KB
50_random_Xilarge_09 WA 1 ms 128 KB
50_random_Xilarge_narrow_00 WA 1 ms 128 KB
50_random_Xilarge_narrow_01 WA 1 ms 128 KB
50_random_Xilarge_narrow_02 WA 1 ms 128 KB
50_random_Xilarge_narrow_03 WA 1 ms 128 KB
50_random_Xilarge_narrow_04 WA 1 ms 128 KB
50_random_Xilarge_narrow_05 WA 1 ms 128 KB
50_random_Xilarge_narrow_06 WA 1 ms 128 KB
50_random_Xilarge_narrow_07 WA 1 ms 128 KB
50_random_Xilarge_narrow_08 WA 1 ms 128 KB
50_random_Xilarge_narrow_09 WA 1 ms 128 KB
50_random_x0small_00 WA 1 ms 128 KB
50_random_x0small_01 WA 1 ms 128 KB
50_random_x0small_02 WA 1 ms 128 KB
50_random_x0small_03 WA 1 ms 128 KB
50_random_x0small_04 WA 1 ms 128 KB
50_random_x0small_05 WA 1 ms 128 KB
50_random_x0small_06 WA 1 ms 128 KB
50_random_x0small_07 WA 1 ms 128 KB
50_random_x0small_08 WA 1 ms 128 KB
50_random_x0small_09 WA 1 ms 128 KB
50_random_x1small_part_00 AC 1 ms 128 KB
50_random_x1small_part_01 AC 1 ms 128 KB
50_random_x1small_part_02 AC 1 ms 128 KB
50_random_x1small_part_03 AC 1 ms 128 KB
50_random_x1small_part_04 AC 1 ms 128 KB
50_random_x1small_part_05 AC 1 ms 128 KB
50_random_x1small_part_06 AC 1 ms 128 KB
50_random_x1small_part_07 AC 1 ms 128 KB
50_random_x1small_part_08 AC 1 ms 128 KB
50_random_x1small_part_09 AC 1 ms 128 KB
80_hand_09 WA 1 ms 128 KB
80_hand_10 WA 1 ms 128 KB
80_hand_part_01 AC 1 ms 128 KB
80_hand_part_02 AC 1 ms 128 KB
80_hand_part_03 AC 1 ms 128 KB
80_hand_part_04 AC 1 ms 128 KB
80_hand_part_05 AC 1 ms 128 KB
80_hand_part_06 AC 1 ms 128 KB
80_hand_part_07 AC 1 ms 128 KB
80_hand_part_08 AC 1 ms 128 KB
80_hand_part_11 AC 1 ms 128 KB
80_hand_part_12 AC 1 ms 128 KB
90_max_no_00 WA 1 ms 128 KB
90_max_no_01 WA 1 ms 128 KB
90_max_yes_00 RE 99 ms 128 KB
90_max_yes_01 RE 102 ms 128 KB
98_challenge_part_00 AC 1 ms 128 KB
98_challenge_part_01 RE 98 ms 128 KB
98_challenge_part_02 AC 1 ms 128 KB
98_challenge_part_03 AC 1 ms 128 KB
98_challenge_part_04 AC 1 ms 128 KB
98_challenge_part_05 AC 1 ms 128 KB