結果

問題 No.3 ビットすごろく
ユーザー shinwisteria
提出日時 2017-03-20 15:30:38
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,023 bytes
コンパイル時間 3,546 ms
コンパイル使用メモリ 78,448 KB
実行使用メモリ 56,368 KB
最終ジャッジ日時 2024-07-05 03:19:38
合計ジャッジ時間 9,746 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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