結果

問題 No.3 ビットすごろく
ユーザー TeraokaAkihiroTeraokaAkihiro
提出日時 2018-06-24 12:09:59
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 639 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 12,432 KB
最終ジャッジ日時 2023-09-13 13:35:28
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,288 KB
testcase_01 AC 7 ms
12,280 KB
testcase_02 AC 7 ms
12,368 KB
testcase_03 AC 7 ms
12,308 KB
testcase_04 WA -
testcase_05 AC 6 ms
12,268 KB
testcase_06 AC 7 ms
12,364 KB
testcase_07 AC 7 ms
12,280 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 7 ms
12,264 KB
testcase_13 AC 7 ms
12,252 KB
testcase_14 AC 7 ms
12,368 KB
testcase_15 AC 7 ms
12,308 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 7 ms
12,316 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 7 ms
12,308 KB
testcase_22 AC 8 ms
12,388 KB
testcase_23 AC 7 ms
12,292 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$c = 1;
$m = 1;
$ma = array(1);
$n = intval(trim(fgets(STDIN)));

if($n === 1){
    print 0;
}else{
    while (true){
        $b =  decbin($m);
        $bc = mb_substr_count($b, '1');
        
        if ($m+$bc > $n){
            $mb = decbin($m+$bc);
            $mbc = mb_substr_count($mb, '1');
            if(array_search($m-$mbc, $ma) === FALSE){
                $bc = 0-$mbc;
            } else {
                print -1;
                break;
            }
        }
        
        $m += $bc;
        $ma[] = $m;
        $c++;
        
        if($m === $n){
            print $c;
            break;
        }
    }
}
?>
0