結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,852 KB
testcase_01 AC 14 ms
18,772 KB
testcase_02 AC 15 ms
18,868 KB
testcase_03 AC 15 ms
18,900 KB
testcase_04 AC 14 ms
18,804 KB
testcase_05 AC 15 ms
18,784 KB
testcase_06 AC 15 ms
18,856 KB
testcase_07 AC 15 ms
18,896 KB
testcase_08 AC 314 ms
18,884 KB
testcase_09 AC 36 ms
18,964 KB
testcase_10 AC 234 ms
18,784 KB
testcase_11 AC 30 ms
18,880 KB
testcase_12 AC 255 ms
18,852 KB
testcase_13 AC 226 ms
18,896 KB
testcase_14 AC 15 ms
18,856 KB
testcase_15 AC 15 ms
18,856 KB
testcase_16 AC 18 ms
18,788 KB
testcase_17 AC 14 ms
18,880 KB
testcase_18 AC 15 ms
18,864 KB
testcase_19 AC 16 ms
18,856 KB
testcase_20 AC 18 ms
18,868 KB
testcase_21 AC 15 ms
18,852 KB
testcase_22 AC 15 ms
18,980 KB
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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,FALSE);
if ( $ret === FALSE ) {
	echo "-1\n";
}
else {
	echo $ret.PHP_EOL;
}

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