結果

問題 No.3 ビットすごろく
ユーザー koukonkokoukonko
提出日時 2015-12-24 22:43:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 77,236 KB
実行使用メモリ 53,976 KB
最終ジャッジ日時 2023-10-19 02:56:04
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

		try {
			int N = Integer.parseInt(buff.readLine());

			int ans = 1; // 移動数
			boolean[] check = new boolean[N];
			int i = 1;
			while (i < N) {
				String str = Integer.toBinaryString(i);
				int count = 0;
				for (int j = 0; j < str.length(); ++j) {
					if (str.charAt(j) == '1') {
						count++;
					}
				}
				if (count + i == N) {
					ans++;
					break;
				} else if (count + i < N) {
					ans++;
					i += count;
					check[i] = true;
				} else if(count + i > N){
					if(check[i - count] || i - count <= 0){
						ans = -1;
						break;
					} else {
						ans++;
						i -= count;
						check[i] = true;
					}
				}
			}
			System.out.println(ans);
		} catch (Exception e) {
			e.getStackTrace();
		}
	}
}
0