結果

問題 No.3 ビットすごろく
ユーザー mell1mell1
提出日時 2018-11-27 22:35:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 65,392 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 17:49:41
合計ジャッジ時間 1,776 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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,p,m;
    queue<int> que;
    cin>>n;
    que.push(i);
    while (1){
        if (i==n) {
            flag = 0;
            break;
        }
        p = i+bpop(i)>n?0:i+bpop(i);
        m = i-bpop(i)>1?i-bpop(i):0;
        if (p&&m&&a[p]&&a[m]) {
            que.pop();
            i=que.front();
            continue;
        }
        if (m > 1 && p && !a[m]) {
            a[m] = a[i] + 1;
            que.push(m);
        }
        if (m && !a[p]) {
            a[p] = a[i] + 1;
            que.push(p);
        }
        que.pop();
        i=que.front();
        if (que.empty()) break;
    }
    if (flag) cout<<-1<<"\n";
    else cout<<a[i]<<"\n";
    return 0;
}
0