結果

問題 No.3 ビットすごろく
ユーザー siguma323siguma323
提出日時 2016-05-05 12:42:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,513 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 78,336 KB
実行使用メモリ 394,368 KB
最終ジャッジ日時 2024-04-15 13:07:43
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 18 ms
24,832 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 84 ms
112,512 KB
testcase_06 AC 22 ms
29,824 KB
testcase_07 AC 8 ms
12,032 KB
testcase_08 AC 53 ms
71,552 KB
testcase_09 AC 141 ms
188,800 KB
testcase_10 AC 195 ms
266,112 KB
testcase_11 AC 116 ms
157,568 KB
testcase_12 AC 79 ms
106,496 KB
testcase_13 AC 13 ms
18,688 KB
testcase_14 AC 182 ms
249,472 KB
testcase_15 AC 282 ms
384,640 KB
testcase_16 AC 239 ms
332,032 KB
testcase_17 AC 271 ms
373,376 KB
testcase_18 AC 10 ms
14,336 KB
testcase_19 AC 287 ms
394,368 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 186 ms
255,488 KB
testcase_23 AC 288 ms
393,984 KB
testcase_24 AC 287 ms
394,112 KB
testcase_25 AC 278 ms
384,896 KB
testcase_26 WA -
testcase_27 AC 16 ms
21,504 KB
testcase_28 AC 231 ms
317,568 KB
testcase_29 AC 120 ms
163,072 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 102 ms
139,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <utility>
#include <cmath>
#include <bitset>

using namespace std;

int now_bit(int num)
{
    bitset<1000> bs(num);
    return bs.count();
}

bool InBounds(int pos,int n)
{
    if(pos > 0 && pos <= n)
        return true;
    else
        return false;
}

int main()
{
    int n;
    cin >> n;

    if(n == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<vector<int>> used(n+1,vector<int>(n+1));
    queue<pair<int,int>> q;
    q.push(make_pair(1 + now_bit(1),1));
    used.at(1).at(1+now_bit(1)) = 1;

    while(!q.empty())
    {
        pair<int,int> index = q.front();
        q.pop();

        if(index.first == n)
        {
            cout << index.second + 1 << endl;
            return 0;
        }

        if(InBounds(index.first + now_bit(index.first),n) && !used.at(index.first).at(index.first + now_bit(index.first)))
        {
            q.push(make_pair(index.first + now_bit(index.first),index.second + 1));
            used.at(index.first).at(index.first + now_bit(index.first)) = 1;
        }

        if(InBounds(index.first - now_bit(index.first),n)  && !used.at(index.first).at(index.first - now_bit(index.first)))
        {
            q.push(make_pair(index.first - now_bit(index.first),index.second + 1));
            used.at(index.first).at(index.first - now_bit(index.first)) = 1;
        }
    }

    cout << -1 << endl;
    return 0;

}
0