結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-06-26 19:29:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 717 bytes |
コンパイル時間 | 121 ms |
コンパイル使用メモリ | 21,888 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 09:42:55 |
合計ジャッジ時間 | 1,189 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 6 | main(){ | ^~~~ main.cpp: In function ‘int main()’: main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d",&N); | ~~~~~^~~~~~~~~
ソースコード
#include<stdio.h> int N; //行ったことがあったら1 int dp[10000]; int getbit(int x); main(){ scanf("%d",&N); int step = 1; int point = 1; while(point != N){ // printf("%d ",point);// //ループ確定 if(dp[point-1]){ step = -1; break; } if(point + getbit(point) <= N){ //前にすすめる場合 step++; dp[point-1] = 1; point += getbit(point); }else{ //後ろに進む step++; dp[point-1] = 1; point -= getbit(point); } } printf("%d",step); return 0; } int getbit(int x){ return __builtin_popcountl(x); }