結果

問題 No.3 ビットすごろく
ユーザー okok
提出日時 2018-08-29 13:56:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 5,000 ms
コード長 782 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 165,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 01:05:59
合計ジャッジ時間 7,054 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 19 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 97 ms
4,376 KB
testcase_06 AC 23 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 58 ms
4,376 KB
testcase_09 AC 169 ms
4,376 KB
testcase_10 AC 236 ms
4,376 KB
testcase_11 AC 139 ms
4,376 KB
testcase_12 AC 90 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 222 ms
4,376 KB
testcase_15 AC 364 ms
4,376 KB
testcase_16 AC 309 ms
4,376 KB
testcase_17 AC 349 ms
4,376 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 372 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 230 ms
4,376 KB
testcase_23 AC 365 ms
4,376 KB
testcase_24 AC 371 ms
4,380 KB
testcase_25 AC 360 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 16 ms
4,380 KB
testcase_28 AC 291 ms
4,376 KB
testcase_29 AC 140 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 117 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 101010101
#define MAX 10000

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<<" "<<k<<" "<<temp2[a]<<endl;//int t;cin>>t;
  if(a==N)return k;
  int temp = huga(a), ans=INF;
  if(a-temp >= 1){
    if(temp2[a-temp] > k){
      temp2[a-temp] = k;
      ans = min(foo(a-temp,k+1), ans);
    }
  }
  if(a+temp <= N){
    if(temp2[a+temp] > k){
      temp2[a+temp] = k;
      ans = min(foo(a+temp,k+1), ans);
    }
  }
  return ans;
}


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