結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-06-03 11:29:04 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 618 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 20,992 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-08 06:13:07 |
合計ジャッジ時間 | 1,173 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:13:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d",&N); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int bit_count(int); int main(void){ int N; int location=1; //現在のマスの位置 int bit=0; // 何ビット進むかor戻るか int sum; int times=1; //移動回数 scanf("%d",&N); while(location != N){ bit = bit_count(location); sum = location + bit; if(sum <= N) location += bit; else location -= bit; times++; sum=0; if(times >= 10000){ printf("-1"); break; } } if(times < 10000) printf("%d",times); return 0; } int bit_count(int n) { int bit_counter=0; while(n>=1) { if(n%2==1) bit_counter++; n=n/2; } return bit_counter; }