結果

問題 No.3 ビットすごろく
ユーザー tottoripaper
提出日時 2014-11-16 01:21:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 55,512 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-31 20:32:20
合計ジャッジ時間 1,573 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>

int N;
bool visited[10001];
int memo[10001];

int dfs(int pos){
    if(pos < 1 || 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),
        res = std::min(dfs(pos-bc)+1, dfs(pos+bc)+1);
    
    visited[pos] = false;
    return memo[pos] = res;
}

int main(int argc, char** argv){
    std::cin >> N;

    std::fill(memo, memo+10001, -1);

    int res = dfs(1);
    if(res < 1001001001){
        printf("%d\n", res);
    }else{
        puts("-1");
    }
}
0