結果

問題 No.3 ビットすごろく
ユーザー DevbotBot
提出日時 2015-07-01 17:20:09
言語 PHP
(843.2)
結果
WA  
実行時間 -
コード長 534 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 32,272 KB
実行使用メモリ 32,272 KB
最終ジャッジ日時 2024-07-07 21:41:03
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = trim(fgets(STDIN));
$map = array_fill(0, $n, -1);
$queue[0] = $map[0] = $step = 1;

while (!empty($queue)) {
		$pos = array_shift($queue);
		$step = $map[$pos -1 ];
		$bit = substr_count(decbin($pos),1,0);
		if ($pos + $bit <= $n && -1 === $map[$pos + $bit -1]){
			$move = $pos + $bit;
			$map[$move -1 ] = $step +1;
			$queue[] = $move;
		}
		if ($pos - $bit > 1 && -1 === $map[$pos - $bit -1]){
			$move = $pos - $bit;
			$map[$move -1 ] = $step +1;
			$queue[] = $move;
		}
}
echo ($n != 1? $map[$n -1 ]: 0) . PHP_EOL;
0