結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  tottoripaper | 
| 提出日時 | 2014-11-16 01:04:06 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 610 bytes | 
| コンパイル時間 | 735 ms | 
| コンパイル使用メモリ | 56,088 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-31 20:32:06 | 
| 合計ジャッジ時間 | 1,688 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 WA * 15 | 
ソースコード
#include <iostream>
#include <cstdio>
int N;
bool visited[10001];
int memo[10001];
int dfs(int pos){
    if(pos < 0 || pos > N){return 1001001001;}
    if(pos == N){return 1;}
    if(visited[pos]){return 1001001001;}
    if(memo[pos] != -1){return memo[pos];}
    visited[pos] = true;
    int bc = __builtin_popcount(pos);
    return memo[pos] = std::min(dfs(pos-bc)+1, dfs(pos+bc)+1);
}
int main(){
    std::cin >> N;
    std::fill(memo, memo+10001, -1);
    int res = dfs(1);
    if(res < 1001001001){
        printf("%d\n", res);
    }else{
        puts("-1");
    }
}
            
            
            
        