結果

問題 No.3 ビットすごろく
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-24 05:20:53
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 3,406 ms
コンパイル使用メモリ 75,172 KB
実行使用メモリ 41,900 KB
最終ジャッジ日時 2024-04-16 10:35:07
合計ジャッジ時間 9,009 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,200 KB
testcase_01 AC 129 ms
41,620 KB
testcase_02 AC 131 ms
41,520 KB
testcase_03 AC 143 ms
41,316 KB
testcase_04 AC 120 ms
40,220 KB
testcase_05 AC 147 ms
41,164 KB
testcase_06 AC 145 ms
41,200 KB
testcase_07 AC 138 ms
41,232 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 145 ms
41,280 KB
testcase_13 AC 147 ms
41,068 KB
testcase_14 AC 141 ms
41,132 KB
testcase_15 AC 144 ms
41,400 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 128 ms
40,560 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 130 ms
41,396 KB
testcase_22 AC 148 ms
41,380 KB
testcase_23 AC 145 ms
41,324 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 130 ms
41,440 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 128 ms
41,284 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;

public class Exercises16{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int goal = sc.nextInt();

    int carol = 1;

    int bitCount = 0;

    int count = 1;

    ArrayList<Integer> blocks = new ArrayList<Integer>();

    blocks.add(carol);

    while (carol != goal){
      bitCount = 0;
      int carolPresent = carol;

      while (carolPresent != 0){
        if (carolPresent % 2 == 1){
          bitCount++;
        }

        carolPresent /= 2;
      }

      if (carol + bitCount > goal){
        carol -= bitCount;
      }else{
        carol += bitCount;
      }

      if (blocks.indexOf(carol) != -1){
        System.out.println(-1);
        return;
      }else{
        blocks.add(carol);
      }

      count += 1;
    }

    System.out.println(count);
  }
}
0