結果

問題 No.3 ビットすごろく
ユーザー kuramubonnkuramubonn
提出日時 2023-02-02 10:31:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 766 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 70,840 KB
実行使用メモリ 58,132 KB
最終ジャッジ日時 2023-09-14 17:42:38
合計ジャッジ時間 7,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,732 KB
testcase_01 AC 123 ms
55,492 KB
testcase_02 AC 125 ms
55,916 KB
testcase_03 AC 124 ms
55,832 KB
testcase_04 AC 126 ms
55,664 KB
testcase_05 AC 126 ms
55,844 KB
testcase_06 AC 126 ms
55,780 KB
testcase_07 AC 124 ms
56,004 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
55,856 KB
testcase_13 AC 125 ms
55,760 KB
testcase_14 AC 129 ms
55,720 KB
testcase_15 AC 128 ms
55,888 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 124 ms
56,240 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 122 ms
56,076 KB
testcase_22 AC 123 ms
55,840 KB
testcase_23 AC 125 ms
56,048 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 123 ms
55,976 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 123 ms
55,740 KB
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;
			}
			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