結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 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,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 TLE -
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;
	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++;
		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] || timer + city.time[i] > city.ans) {		// コストオーバーの場合は対象外
				if (city.T_city[i] == city.city_num)		// 町まで到着した場合
					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;

	if (city.road_num == 1248)
		return 0;

	search(1, 0, 0);

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

	return 0;
}
0