結果
| 問題 | 
                            No.3 ビットすごろく
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-02-10 01:57:15 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,126 bytes | 
| コンパイル時間 | 1,704 ms | 
| コンパイル使用メモリ | 172,156 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-07 10:31:19 | 
| 合計ジャッジ時間 | 2,312 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 9 WA * 24 | 
ソースコード
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector<bool>seen;
int dfs(int now, int target, int count) {
    if (now == target) {
        return count;
    }
    seen[now] = true;
    int b_c = __builtin_popcount(now);
    int s = seen.size();
    int tmp = 100000;
    bool can_do = false;
    if (s > now+b_c && !seen[now+b_c]) {
        tmp = min(tmp, dfs(now+b_c, target, count+1));
        can_do = true;
    }
    if (now-b_c>0 && !seen[now-b_c]) {
        can_do = true;
        int n = dfs(now-b_c, target, count+1);
        if (tmp == -1) {
            tmp = n;
        } else if (n == -1) {
            // nannmosen
        } else {
            tmp = min(tmp, n);
        }
    }
    if (!can_do) {
        tmp = -1;
    }
    return tmp;
}
int main()
{
    int N;
    cin >> N;
    seen.resize(N+1);
    int count = dfs(1, N, 1);
    cout << count << endl;
    return 0;
}