結果

問題 No.3 ビットすごろく
ユーザー Fu_LFu_L
提出日時 2020-06-17 22:02:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 574 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 163,276 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2023-09-16 11:43:51
合計ジャッジ時間 8,482 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 406 ms
4,376 KB
testcase_04 AC 16 ms
4,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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]>ans[i]){
        ans[i-c]=ans[i]+1;
        solve(i-c);
    }
    if(i+c<=n&&ans[i+c]>ans[i]){
        ans[i+c]=ans[i]+1;
        solve(i+c);
    }
}
int main(void){
    cin>>n;
    ans[1]=1;
    for(int i=2;i<=n;i++){
        ans[i]=1000000000;
    }
    solve(1);
    if(ans[n]==1000000000){
        ans[n]=-1;
    }
    cout<<ans[n]<<endl;
    
}
0