結果

問題 No.3 ビットすごろく
ユーザー かぼちゃかぼちゃ
提出日時 2018-04-20 23:21:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 292 ms / 5,000 ms
コード長 981 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 77,300 KB
実行使用メモリ 6,128 KB
最終ジャッジ日時 2023-09-14 00:59:05
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 44 ms
4,376 KB
testcase_10 AC 115 ms
4,380 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 96 ms
4,376 KB
testcase_15 AC 252 ms
5,080 KB
testcase_16 AC 146 ms
4,376 KB
testcase_17 AC 225 ms
5,484 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 290 ms
6,072 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 101 ms
4,376 KB
testcase_23 AC 291 ms
5,564 KB
testcase_24 AC 292 ms
6,128 KB
testcase_25 AC 252 ms
5,236 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 136 ms
4,380 KB
testcase_29 AC 29 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 18 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>

#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define REP(i,a,n) for(int i = (a);i < (n);i++)
#define PI 3.14159265359
#define MOD 1000000007
#define chmax(a,b) if(a < b)a = b

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1,-1);
    queue<pair<int,int>> q;
    q.push({1,1});
    while(!q.empty()){
        int index = q.front().first;
        int count = q.front().second;
        a[index] = count;
        if(index == n)break;
        
        int add = 0,b = index;
        while(b > 0){
            add += b % 2;
            b /= 2;
        }
        
        if(a[index + add] == -1 && index + add <= n) q.push({index + add,count + 1});
        if(a[index - add] == -1 && index - add > 0) q.push({index - add,count + 1});
        q.pop();
    }
    cout << a[n] << endl;
    return 0;
}
0