結果

問題 No.1 道のショートカット
ユーザー ReERishunReERishun
提出日時 2020-05-09 03:21:54
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,579 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 29,368 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-09-22 13:44:22
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 25 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>

typedef unsigned short ushort;

struct city_info {
	ushort city_num;
	ushort money;
	ushort road_num;
	ushort S_city[1500];
	ushort T_city[1500];
	ushort cost[1500];
	ushort time[1500];
	unsigned int ans;
};

struct city_info city;

void numin(ushort index, ushort numBox[1500]) {
	char str;
	for (ushort i = 0; i<index; i++)
		numBox[i] = 0;
	ushort cnt = 0;
	ushort strcnt = 0;
	while (cnt < index) {
		str = getchar();
		if (str == '\n' && cnt == 0) {
			continue;
		}
		else if (str == '\n' && cnt != 0) {
			break;
		}
		else if (str < '0' || str > '9') {
			cnt++;
			strcnt = 0;
		}
		else
			numBox[cnt] = numBox[cnt] * 10 + (ushort)str - (ushort)'0';
	}
}


int search(ushort S_num, ushort cost, ushort timer) {
	for (short i = 0;i < city.road_num; i++) {
		if (city.S_city[i] == S_num) {
			if (city.money >= cost + city.cost[i]) {		// コストオーバーの場合は対象外
				if (city.T_city[i] == city.city_num) {		// 町まで到着した場合
					if (timer + city.time[i] < city.ans)	// 記録より速いか?
						city.ans = timer + city.time[i];
				}else {
					search(city.T_city[i], cost + city.cost[i], timer + city.time[i]);
				}
			}
		}
	}
	return 0;
}

int main() {

	scanf("%d", &city.city_num);
	scanf("%d", &city.money);
	scanf("%d", &city.road_num);

	numin(city.road_num, city.S_city);
	numin(city.road_num, city.T_city);
	numin(city.road_num, city.cost);
	numin(city.road_num, city.time);

	city.ans = 1500001;

	search(1, 0, 0);

	if (city.ans == 1500001)
		printf("-1");
	else
		printf("%d", city.ans);

	return 0;
}
0