結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,748 KB
testcase_01 AC 15 ms
18,816 KB
testcase_02 AC 15 ms
18,748 KB
testcase_03 AC 17 ms
18,780 KB
testcase_04 WA -
testcase_05 AC 16 ms
18,600 KB
testcase_06 AC 16 ms
18,724 KB
testcase_07 AC 15 ms
18,564 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 15 ms
18,596 KB
testcase_13 AC 14 ms
18,776 KB
testcase_14 AC 16 ms
18,596 KB
testcase_15 AC 16 ms
18,760 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 15 ms
18,736 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
18,716 KB
testcase_22 AC 16 ms
18,588 KB
testcase_23 AC 16 ms
18,684 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