結果

問題 No.3 ビットすごろく
ユーザー Fu_L
提出日時 2020-06-17 21:59:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 468 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 166,268 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-03 12:29:13
合計ジャッジ時間 2,228 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll ans[10005];
void solve(ll i){
    ll c=0,j=i;
    while(j>0){
        c=c+j%2;
        j=j/2;
    }
    if(i-c>=1&&ans[i-c]<=0){
        ans[i-c]=ans[i]+1;
        solve(i-c);
    }
    if(i+c<=n&&ans[i+c]<=0){
        ans[i+c]=ans[i]+1;
        solve(i+c);
    }
}
int main(void){
    cin>>n;
    ans[1]=1;
    ans[n]=-1;
    solve(1);
    cout<<ans[n]<<endl;
    
}
0