結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 57 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 283 ms
4,376 KB
testcase_06 AC 73 ms
4,376 KB
testcase_07 AC 25 ms
4,376 KB
testcase_08 AC 177 ms
4,376 KB
testcase_09 AC 504 ms
4,376 KB
testcase_10 AC 655 ms
4,564 KB
testcase_11 AC 397 ms
4,384 KB
testcase_12 AC 271 ms
4,376 KB
testcase_13 AC 40 ms
4,376 KB
testcase_14 AC 665 ms
4,564 KB
testcase_15 AC 1,038 ms
4,764 KB
testcase_16 AC 828 ms
4,740 KB
testcase_17 AC 1,010 ms
4,784 KB
testcase_18 AC 32 ms
4,376 KB
testcase_19 AC 1,056 ms
4,764 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 677 ms
4,504 KB
testcase_23 AC 972 ms
4,764 KB
testcase_24 AC 978 ms
4,764 KB
testcase_25 AC 1,022 ms
4,752 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 425 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 352 ms
4,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int solve(int p, int q){

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

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

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

int main(){

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