結果

問題 No.3 ビットすごろく
ユーザー tazakkytazakky
提出日時 2017-09-01 11:12:40
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 721 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 30,840 KB
実行使用メモリ 32,404 KB
最終ジャッジ日時 2024-04-24 09:51:19
合計ジャッジ時間 6,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
32,404 KB
testcase_01 AC 42 ms
31,004 KB
testcase_02 AC 41 ms
31,104 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
    $n = trim(fgets(STDIN));
    
    //開始のマスがすでにゴール
    if($n == 1){
        echo 1;
        exit;
    }
    
    for($i = 1; $i < $n; $i++){
        $line[$i] = decbin($i);
    }
    $line[] = "x";
    //print_r($line);
    
    $i = 2;
    $count = 2;
    while($line[$i] != "x" ){
        //echo $i."-".$line[$i]."\n";
        $count++;
        $bin = $line[$i];
        if($i + mb_substr_count($bin, "1") <= $n ) {
            $i = $i + mb_substr_count($bin, "1");
        }else{
            $i = $i - mb_substr_count($bin, "1");
        }
        
        //1に戻たらストップ
        if($i == 1){
            $count = -1;
            break;
        }
    }
    echo $count;
?>
0