結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-12-02 11:33:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 999 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 23,168 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-27 17:10:44 |
合計ジャッジ時間 | 4,386 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 4 RE * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d",&goal); | ~~~~~^~~~~~~~~~~~
ソースコード
#include<stdio.h> int numOfBits(int n){ int bits=0; do{ bits += n %2; n /= 2; }while(n>0); return bits; } int main(){ int goal; scanf("%d",&goal); int isPassed[goal+1]; isPassed[0]=1; int q[100000]; q[0]=1; q[1]=-1; int q_head=0,q_tail=1; int position; int back,forward; int depth = 1; do{ if(q[q_head]==-1){ depth++; q_head++; q[q_tail+1]=-1; q_tail++; continue; } position = q[q_head]; q_head++; back = position - numOfBits(position); forward = position + numOfBits(position); isPassed[position]=1; // printf("position:%2d depth:%2d\n",position,depth); // printf("back:%2d forward:%2d\n\n",back,forward); if(back==goal || forward==goal){ printf("%d\n",depth+1); break; } if(isPassed[back]!=1){ q[q_tail+1]=back; q_tail++; } if(isPassed[forward]!=1){ q[q_tail+1]=forward; q_tail++; } }while(1); //printf("%d\n",numOfBits(n)); //printf("%d %d",isPassed[0],isPassed[n]); return 0; }