結果

問題 No.3 ビットすごろく
ユーザー 綾地寧々綾地寧々
提出日時 2015-05-20 19:30:37
言語 PHP
(8.3.4)
結果
AC  
実行時間 113 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 18,428 KB
実行使用メモリ 20,940 KB
最終ジャッジ日時 2023-09-13 23:09:50
合計ジャッジ時間 4,271 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,872 KB
testcase_01 AC 16 ms
18,756 KB
testcase_02 AC 15 ms
18,756 KB
testcase_03 AC 26 ms
18,836 KB
testcase_04 AC 17 ms
18,744 KB
testcase_05 AC 50 ms
18,916 KB
testcase_06 AC 28 ms
18,732 KB
testcase_07 AC 21 ms
18,812 KB
testcase_08 AC 41 ms
18,608 KB
testcase_09 AC 67 ms
20,884 KB
testcase_10 AC 92 ms
20,772 KB
testcase_11 AC 60 ms
18,564 KB
testcase_12 AC 50 ms
18,584 KB
testcase_13 AC 24 ms
18,608 KB
testcase_14 AC 89 ms
20,940 KB
testcase_15 AC 109 ms
20,680 KB
testcase_16 AC 103 ms
20,824 KB
testcase_17 AC 109 ms
20,768 KB
testcase_18 AC 22 ms
18,748 KB
testcase_19 AC 113 ms
20,852 KB
testcase_20 AC 17 ms
18,812 KB
testcase_21 AC 15 ms
18,752 KB
testcase_22 AC 89 ms
20,840 KB
testcase_23 AC 105 ms
20,876 KB
testcase_24 AC 105 ms
20,860 KB
testcase_25 AC 111 ms
20,856 KB
testcase_26 AC 15 ms
18,744 KB
testcase_27 AC 25 ms
18,832 KB
testcase_28 AC 106 ms
20,768 KB
testcase_29 AC 61 ms
18,756 KB
testcase_30 AC 16 ms
18,760 KB
testcase_31 AC 16 ms
18,680 KB
testcase_32 AC 55 ms
18,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = trim(fgets(STDIN));
$visited = array();
$maxtime = -1;
move(1,1,1);
echo $maxtime.PHP_EOL;

function move ( $prev, $start, $time ) {
	global $n, $visited, $maxtime;
	if ( ($start < 1) || ($start > $n) ) {				// 範囲外
		return;
	}
	if ( ($maxtime != -1) && ($maxtime <= $time) ) {	// 移動回数多すぎ
		return;
	}
	
	// ゴール到着
	if ( $start == $n ) {
		$maxtime = $time;
		return;
	}
	
	if ( isset($visited[$start-1]) === TRUE ) {			// 訪問済
		if ( $visited[$start-1] <= $time ) {			// ルート問わず、高コストで到達してしまった
			return;
		}
	}
	$visited[$start-1] = $time;
	$bit = decbin($start);
	$counts = count_chars($bit, 1);
	$count = $counts[ord('1')];
	$time++;
	if ( ($start+$count) != $prev ) {
		move($start, $start+$count, $time);
	}
	if ( ($start-$count) != $prev ) {
		move($start, $start-$count, $time);
	}
	
	return;
}
0