結果

問題 No.3 ビットすごろく
ユーザー kenji_shioyakenji_shioya
提出日時 2016-05-24 04:56:49
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 698 bytes
コンパイル時間 3,250 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 61,016 KB
最終ジャッジ日時 2024-04-16 10:34:38
合計ジャッジ時間 10,225 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
40,996 KB
testcase_01 AC 132 ms
41,176 KB
testcase_02 AC 129 ms
41,120 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

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;

    if (goal % 4 == 0){
      System.out.println(-1);
      return;
    }

    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;
      }

      count += 1;
    }

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