結果

問題 No.3 ビットすごろく
ユーザー kuramubonnkuramubonn
提出日時 2023-02-02 10:30:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 809 bytes
コンパイル時間 3,427 ms
コンパイル使用メモリ 74,684 KB
実行使用メモリ 59,232 KB
最終ジャッジ日時 2023-09-14 17:41:39
合計ジャッジ時間 10,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sub s = new sub();
		int goal = sc.nextInt();
		int num = 1,cnt = 0;
		
		boolean[] flug = new boolean [goal];
		flug[0] = true;
		
		while(num < goal) {
			int t = s.counter(num);
			if(t + num > goal) {//ゴールを超える場合
				num -= t;
			}else {
				num += t;
			}
			
			if(flug[num - 1] == true) {//同じところに2回訪れたら到達不可能
				System.out.println(-1);
				return;
			}else {
				flug[num - 1] = true;
			}
			
			System.out.println(cnt + ":" + num);
			cnt++;
		}
		
		System.out.println(cnt + 1);
	}
}

class sub{
	int counter(int num) {
		int count = 0;
		for(int i = num ; i > 0 ; i = i / 2) {
			if(i % 2 == 1) count++;
		}
		return count;
	}
}
0