結果

問題 No.3 ビットすごろく
ユーザー satanic
提出日時 2015-11-23 21:55:17
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 519 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 21,376 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 17:18:56
合計ジャッジ時間 1,272 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~

ソースコード

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