結果

問題 No.3 ビットすごろく
ユーザー mustonmuston
提出日時 2016-05-16 15:42:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 74,008 KB
実行使用メモリ 41,740 KB
最終ジャッジ日時 2024-04-15 22:26:55
合計ジャッジ時間 7,708 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,572 KB
testcase_01 AC 130 ms
41,236 KB
testcase_02 AC 127 ms
41,328 KB
testcase_03 AC 129 ms
41,012 KB
testcase_04 AC 129 ms
41,096 KB
testcase_05 AC 131 ms
41,212 KB
testcase_06 AC 130 ms
41,416 KB
testcase_07 AC 128 ms
40,996 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 130 ms
41,248 KB
testcase_13 AC 118 ms
40,192 KB
testcase_14 AC 132 ms
41,704 KB
testcase_15 AC 132 ms
41,252 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 132 ms
41,472 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 132 ms
41,476 KB
testcase_22 AC 120 ms
40,084 KB
testcase_23 AC 135 ms
41,628 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 130 ms
41,696 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 130 ms
41,400 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
/*yukicoder No.3 ビットすごろく*/
class No3{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    //ゴールまでのマスnを入力
    int n = scan.nextInt();
    int[] log = new int[n];
    int here = 1;  //今のマスの位置
    int move = 0;  //移動する数(マス)
    int count = 1;  //移動した回数
    while(n!=here){
      count += 1;
      move = Integer.bitCount(here);//今のマス数を2進数にしたときの1の数
      if(n<here+move){
        //ゴールマスを超えるときはその数だけ戻る
        here-=move;
      }else{
        here+=move;
      }
      if(log[here-1] == 1){
        //同じ場所に来たらループから抜ける
        count= -1;
        break;
      }else{
        log[here-1] = 1;
      }
      //ゴールマスに止まったらループから抜ける
      if(log[n-1] == 1)
        break;
    }
    //ゴールまでの移動回数を出力
    System.out.println(count);
  }
}
0