結果

問題 No.3 ビットすごろく
ユーザー tamarontamaron
提出日時 2019-12-18 14:09:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 151,028 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 14:45:47
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 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 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const long long INF = 1e18;

vector<ll> dp(10100,0);
vector<bool> visited(10100,false);
queue<ll> que;

ll stands(ll num){
    ll cnt=0;
    while(num>0){
        if(num%2==1) ++cnt;
        num/=2;
    }
    return cnt;
}

int main() {
    ll N;
    cin>>N;
    que.push(1);
    dp[1]=1;
    while(!que.empty()){
        ll node=que.front();que.pop();
        if(visited[node]) continue;
        visited[node]=true;
        ll st=stands(node);
        if (0<node-st && node-st<=N){
            dp[node-st]=dp[node]+1;
            que.push(node-st);
        }
        if (0<node+st && node+st<=N){
            dp[node+st]=dp[node]+1;
            que.push(node+st);
        }
    }
    if (dp[N]==0) cout<<-1<<endl;
    else cout<<dp[N]<<endl;

    return 0;
}
0