結果

問題 No.3 ビットすごろく
ユーザー shinwisteriashinwisteria
提出日時 2017-03-20 15:00:38
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 847 bytes
コンパイル時間 3,407 ms
コンパイル使用メモリ 74,268 KB
実行使用メモリ 838,356 KB
最終ジャッジ日時 2023-09-18 12:27:31
合計ジャッジ時間 6,223 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,424 KB
testcase_01 AC 125 ms
55,804 KB
testcase_02 AC 124 ms
55,396 KB
testcase_03 MLE -
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 Bitsugoroku {
	static int N;
	static boolean tof = false;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int p = 1,count = 1;
		N = s.nextInt();
		s.close();
		if(N == 1){
			count = 1;
		}else{
			int h = Sugo(p,count);
			if(h == 0){
				count = 0;
			}else{ 
				count += h;
			}
		}
		if(count == 0){	
			System.out.println(-1);
		}else{
			System.out.println(count);
		}
	}
	static int Sugo(int p,int count){
		int d = Integer.bitCount(p);
		if(p + d > N){
			tof = true;
			int k = Sugo(p - d,count);
			if(k == 0){
				count = 0;
			}else{
				count += k;
			}
		}else if(p + d == N){
			count = 1;
		}else if(p - d <= 3 && tof){
			count = 0;
		}else{
			int h = Sugo(p+d,count);
			if(h==0){
				count = 0;
			}else{
				count += h;
			}
		}
		return count;
	}
}
0