結果

問題 No.3 ビットすごろく
ユーザー ko_ki_leoko_ki_leo
提出日時 2015-10-11 19:10:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 539 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 143,388 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-28 11:49:21
合計ジャッジ時間 2,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int n;
int memo[11111];
bool flg[11111];
int k;

int solve(int p){

  if(p == n) return 1;
  if(p < 1 || p > n) return 1<<28;
  //if(memo[p]) return memo[p];
  if(flg[p]) return 1<<28;
  
  flg[p] = true;  

  int cnt = 0;
  for(int i=0;i<32;i++)
    if((p & (1 << i))) cnt++;

  int ret = 0;
  ret += min(solve(p-cnt), solve(p+cnt)) + 1;
  
  return memo[p] = ret;
}

int main(){

  int ans;
  
  cin >> n;
  
  ans = solve(1);
  if(ans >= 1<<28) puts("-1");
  else cout << ans << endl;
  
}
0