結果

問題 No.1 道のショートカット
ユーザー 綾地寧々綾地寧々
提出日時 2015-05-14 19:10:24
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 1,342 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 18,432 KB
実行使用メモリ 23,304 KB
最終ジャッジ日時 2023-09-22 12:11:10
合計ジャッジ時間 10,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,884 KB
testcase_01 AC 17 ms
18,888 KB
testcase_02 AC 17 ms
18,956 KB
testcase_03 AC 17 ms
18,888 KB
testcase_04 AC 17 ms
18,784 KB
testcase_05 AC 17 ms
18,856 KB
testcase_06 AC 17 ms
18,912 KB
testcase_07 AC 17 ms
18,900 KB
testcase_08 AC 573 ms
18,900 KB
testcase_09 AC 52 ms
18,664 KB
testcase_10 AC 1,189 ms
18,916 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$g_towns = trim(fgets(STDIN));
$g_money = trim(fgets(STDIN));
$g_roads = trim(fgets(STDIN));
$g_departure = explode(" ",trim(fgets(STDIN)));
$g_arrival = explode(" ",trim(fgets(STDIN)));
$g_cost = explode(" ",trim(fgets(STDIN)));
$g_time = explode(" ",trim(fgets(STDIN)));

$ret = move(1,$g_money,0);
if ( $ret === FALSE ) {
	echo "-1\n";
}
else {
	echo $ret.PHP_EOL;
}

// 移動をおこなう関数
function move($start, $money, $time) {
	global $g_towns,$g_money,$g_roads,$g_departure,$g_arrival,$g_cost,$g_time;
	// ----- 再帰呼出し終了条件の判定 ----------
	// コストが最大値を超えてしまった場合
	if ( $money < 0 ) {
		return FALSE;
	}
	// 最後の街に到着した場合
	else if ( $start == $g_towns ) {
		return $time;
	}
	// ----- 再帰呼出しをおこなう ------------
	$min = FALSE;
	foreach ( $g_departure as $index => $dep ) {
		// 行き先が見つかった
		if ( $dep == $start ) {
			$newtime = move($g_arrival[$index],$money-$g_cost[$index],$time+$g_time[$index]);
			if ( $newtime === FALSE ) {
				// 今回のルートでは最後まで辿りつけなかったので何もしない。
			}
			else if ( $min === FALSE ) {
				$min = $newtime;
			}
			else {
				$min = min($min, $newtime);
			}
		}
	}
	// ----- 探した最短時間での結果を返却する
	return $min;
}
0