結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
n120aosssssssss
|
| 提出日時 | 2017-05-21 21:51:40 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 5,000 ms |
| コード長 | 501 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 32,400 KB |
| 実行使用メモリ | 32,656 KB |
| 最終ジャッジ日時 | 2024-07-01 08:43:09 |
| 合計ジャッジ時間 | 2,533 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php
$N = trim(fgets(STDIN));
$route = array_fill(0, $N, -1);
$route[0] = $queue[0] = 1;
while(!empty($queue)) {
$pos = array_shift($queue);
$move = substr_count(decbin($pos), 1);
$next = $pos + $move;
$prev = $pos - $move;
if($next <= $N && $route[$next - 1] === -1) {
$route[$next - 1] = $route[$pos - 1] + 1;
$queue[] = $next;
}
if($prev > 1 && $route[$prev - 1] === -1) {
$route[$prev - 1] = $route[$pos - 1] + 1;
$queue[] = $prev;
}
}
echo $route[$N -1].PHP_EOL;
n120aosssssssss