結果

問題 No.3 ビットすごろく
ユーザー shinwisteriashinwisteria
提出日時 2017-03-20 15:30:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,023 bytes
コンパイル時間 3,895 ms
コンパイル使用メモリ 76,660 KB
実行使用メモリ 57,572 KB
最終ジャッジ日時 2023-09-18 12:28:22
合計ジャッジ時間 9,884 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,840 KB
testcase_01 AC 126 ms
53,872 KB
testcase_02 AC 127 ms
56,032 KB
testcase_03 AC 146 ms
55,656 KB
testcase_04 AC 127 ms
55,604 KB
testcase_05 AC 151 ms
55,592 KB
testcase_06 AC 151 ms
55,520 KB
testcase_07 AC 137 ms
55,772 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 148 ms
55,904 KB
testcase_13 AC 147 ms
55,748 KB
testcase_14 AC 149 ms
56,036 KB
testcase_15 AC 150 ms
55,692 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 138 ms
55,952 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 126 ms
55,664 KB
testcase_22 AC 148 ms
55,816 KB
testcase_23 AC 152 ms
56,148 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 125 ms
56,164 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 125 ms
55,792 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Bitsugoroku {
	static int N;
	static boolean tof = false;
	static ArrayList<Integer> list = new ArrayList<>();

	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(list.contains(p)){
			return 0;
		}
		list.add(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{
			int ph = Sugo(p+d,count);
			if(ph>0){
				count += ph;
			}else{
				int nh = Sugo(p+d,count);
				if(nh > 0){
					count += nh;
				}else{
					count = 0;
				}
			}
		}
		return count;
	}
}
0