結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2016-06-03 13:43:18 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 501 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 20,736 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 06:16:51 |
合計ジャッジ時間 | 1,084 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:12:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d",&N); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int fnBitCount(int); int main(void){ int N; int location=1; int bit=0; int times=1; scanf("%d",&N); while(location != N) { bit = fnBitCount(location); if((bit+location) <= N) location += bit; else location -= bit; times++; if(times >= 10000){ printf("-1"); break; } } if(times < 10000) printf("%d",times); return 0; } int fnBitCount(int n) { int bit_counter=0; while(n>=1) { if(n%2==1) bit_counter++; n/=2; } return bit_counter; }