結果

問題 No.3 ビットすごろく
ユーザー okok
提出日時 2018-08-29 13:43:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 727 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 164,084 KB
実行使用メモリ 7,688 KB
最終ジャッジ日時 2023-10-11 15:25:52
合計ジャッジ時間 8,839 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
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;
#define int long long
#define INF 101010101


int N, temp2[11000];

int huga(int a){
  int ans=0;
  while(a){
    if(a%2)ans++;
    a/=2;
  }
  return ans;
}


int foo(int a, int k){//cout<<a<<endl;
  if(a==N)return k;
  int temp = huga(a), ans=INF;
  if(a-temp >= 1){
    if(temp2[a-temp]==0){
      temp2[a-temp] = 1;
      ans = min(foo(a-temp,k+1), ans);
      temp2[a-temp] = 0;
    }
  }
  if(a+temp <= N){
    if(temp2[a+temp]==0){
      temp2[a+temp] = 1;
      ans = min(foo(a+temp,k+1), ans);
      temp2[a+temp] = 0;
    }
  }
  return ans;
}


signed main(){
  cin>>N;
  int ans = foo(1,1); temp2[1]=1;
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}
0