結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  siguma323 | 
| 提出日時 | 2016-05-05 12:42:54 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,513 bytes | 
| コンパイル時間 | 652 ms | 
| コンパイル使用メモリ | 78,380 KB | 
| 実行使用メモリ | 394,240 KB | 
| 最終ジャッジ日時 | 2024-10-05 09:31:30 | 
| 合計ジャッジ時間 | 5,099 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 WA * 1 | 
ソースコード
#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;
}
            
            
            
        