結果

問題 No.3 ビットすごろく
ユーザー siguma323siguma323
提出日時 2016-05-05 12:43:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 334 ms / 5,000 ms
コード長 1,513 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 78,448 KB
実行使用メモリ 394,064 KB
最終ジャッジ日時 2023-09-13 23:52:12
合計ジャッジ時間 6,459 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 20 ms
24,668 KB
testcase_04 AC 4 ms
5,168 KB
testcase_05 AC 95 ms
112,308 KB
testcase_06 AC 24 ms
29,644 KB
testcase_07 AC 10 ms
11,876 KB
testcase_08 AC 59 ms
71,344 KB
testcase_09 AC 156 ms
188,560 KB
testcase_10 AC 212 ms
266,028 KB
testcase_11 AC 133 ms
157,580 KB
testcase_12 AC 89 ms
106,304 KB
testcase_13 AC 15 ms
18,544 KB
testcase_14 AC 199 ms
249,544 KB
testcase_15 AC 333 ms
384,632 KB
testcase_16 AC 275 ms
331,764 KB
testcase_17 AC 307 ms
373,552 KB
testcase_18 AC 12 ms
14,400 KB
testcase_19 AC 324 ms
394,064 KB
testcase_20 AC 2 ms
4,472 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 211 ms
255,472 KB
testcase_23 AC 321 ms
393,740 KB
testcase_24 AC 334 ms
394,000 KB
testcase_25 AC 308 ms
384,776 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 18 ms
21,184 KB
testcase_28 AC 260 ms
317,508 KB
testcase_29 AC 136 ms
163,060 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 114 ms
138,980 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 << 1 << 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