結果

問題 No.3 ビットすごろく
コンテスト
ユーザー Ai3Shota
提出日時 2018-06-14 23:36:53
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 768 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,158 ms
コンパイル使用メモリ 180,204 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-20 16:48:18
合計ジャッジ時間 2,205 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

int N;
vector<int> bit(10001, 0);
vector<int> dp(10001, -1);
bool flag = false;

int Count(int i){
    int res = 0;
    while(i > 0){
       if(i % 2 == 1) ++res;
       i /= 2;
    }
    return res;
}

void rec(int count = 1, int corrent = 1){
    
    if(~dp[corrent]) return ;
    dp[corrent] = count;
    
    if(corrent == N){
        cout << count << endl;
        flag = true;
        return;
    }
    
    int c;
    if((c = corrent + bit[corrent]) <= N) rec(count + 1, c);
    if((c = corrent - bit[corrent]) >= 1) rec(count + 1, c);
    
    return;
}

int main(void){
    
    cin >> N;
    for(int i = 1; i <= N; ++i) bit[i] = Count(i);
    
    rec();
    if(!flag) cout << -1 << endl; 
    
    return 0;
}
0