結果

問題 No.3 ビットすごろく
ユーザー A63635985A63635985
提出日時 2018-03-06 23:07:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,080 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 75,604 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:56:42
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
using namespace std;
int bit(int x){
        int response=(x%2);
        while(x/=2)
                response+=(x%2);
        return response;
}
struct Struct{
        int n,count;
        Struct(int n=0,int count=0):n(n),count(count){};
};
int main(){
        int N;
        cin >> N;
        queue<Struct> circle;
        circle.push(Struct(1,1));
        map<int,bool> dp;
        bool sign=false;
        Struct now;
        while(circle.size()!=0){
                now=circle.front();circle.pop();
                if(now.n==N){
                        sign=true;
                        break;
                }
                if(dp[now.n]!=0)continue;
                if(now.n<0 || now.n>N)continue;
                dp[now.n]=true;
                int step=bit(now.n);
                circle.push(Struct(now.n-step,now.count+1));
                circle.push(Struct(now.n+step,now.count+1));
        }
        if(sign)
                cout<<now.count<<endl;
        else
                cout<<-1<<endl;
        return 0;
}
0