結果

問題 No.3 ビットすごろく
ユーザー satanicsatanic
提出日時 2015-11-23 21:55:17
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 519 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 23,880 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-11 18:24:32
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int fnCheckOneNum(int n){
  int result=0;
  while(n>0){
    if(n%2==1) ++result;
    n/=2;
  }
  return result;
}

int main(){
  int n;
  int now=1, now_tmp;
  int d, i=0, j;
  int move_cnt=1, back_cnt=0;
  
  scanf("%d", &n);
  while(now!=n){
    d=fnCheckOneNum(now);
    if(now+d<=n)now+=d;
    else{
      ++i;
      ++back_cnt;
      for(j=0; j<back_cnt; ++j){
	now-=d;
	if(now<1){
	  printf("-1\n");
	  return 0;
	}
      }
    }

    ++move_cnt;
  }
  printf("%d\n", move_cnt);

  return 0;
}
0