結果

問題 No.3 ビットすごろく
ユーザー mell1mell1
提出日時 2018-11-27 22:16:09
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 720 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 65,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 15:54:38
合計ジャッジ時間 7,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
using namespace std;
int bpop(int n){
    int m=n%2;
    for(;n/=2;)m+=n%2;
    return m;
}
int main(){
    int a[10001]={0,1},n,i=1,flag=-1;
    queue<int> que;
    cin>>n;
    que.push(i);
    while (1){
        if (i==n) {
            flag = 0;
            break;
        }
        if (i-bpop(i) > 1 && i-bpop(i) <= n) {
            a[i-bpop(i)] = a[i] + 1;
            que.push(i-bpop(i));
        }
        if (i+bpop(i) > 1 && i+bpop(i) <= n) {
            a[i+bpop(i)] = a[i] + 1;
            que.push(i+bpop(i));
        }
        que.pop();
        if (que.empty()) break;
        i=que.front();
    }
    if (flag) cout<<-1<<"\n";
    else cout<<a[i]<<"\n";
    return 0;
}
0