結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  Bantako | 
| 提出日時 | 2017-06-26 19:29:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 717 bytes | 
| コンパイル時間 | 104 ms | 
| コンパイル使用メモリ | 22,144 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-04 09:42:48 | 
| 合計ジャッジ時間 | 950 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | WA * 33 | 
コンパイルメッセージ
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("\n%d",step);
    return 0;
}
int getbit(int x){
     return __builtin_popcountl(x);
}
            
            
            
        