結果

問題 No.3 ビットすごろく
ユーザー hj5ln8kbDM8t2fFhj5ln8kbDM8t2fF
提出日時 2019-07-28 19:01:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 74,340 KB
実行使用メモリ 59,140 KB
最終ジャッジ日時 2023-09-15 11:36:31
合計ジャッジ時間 10,076 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,628 KB
testcase_01 WA -
testcase_02 AC 122 ms
55,880 KB
testcase_03 AC 167 ms
57,036 KB
testcase_04 WA -
testcase_05 AC 178 ms
56,740 KB
testcase_06 AC 167 ms
55,508 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 177 ms
57,156 KB
testcase_13 AC 167 ms
59,140 KB
testcase_14 AC 192 ms
57,068 KB
testcase_15 AC 208 ms
57,068 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 191 ms
57,312 KB
testcase_23 AC 210 ms
56,884 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.Console;
import java.util.*;

	public class No3 {
	    public static void main(String[] args){
	        Scanner sc =new Scanner(System.in);
	        int N = sc.nextInt();

	        int list[] = new int[N + 15];
	        List<Integer> q1 = new ArrayList<Integer>();
	        List<Integer> q2 = new ArrayList<Integer>();
	        
	        q1.add(1);
	        int count = 0;
	        int i = 0;
	        
	        while(i<1){
	            q1.addAll(q2);
	            q2.clear();

	            for(int Num : q1){
	                int one = Integer.bitCount(Num);
	                if(Num-one>0){
	                    if(list[Num-one]==0){
	                        count=count+1;
	                        list[Num-one]=count;
	                        q2.add(Num-one);
	                    }
	                }
	                if(Num+one<=N){
	                    if(list[Num+one]==0){
	                        count=count+1;
	                        list[Num+one]=count;
	                        q2.add(Num+one);
	                    }
	                }
	            }
	            if(list[N]!=0){
	                System.out.println(list[N]);
	                i = i+1;
	                break;
	            }else if(q2.isEmpty()){
	                System.out.println(-1);
	                i = i+1;
	                break;
	            }
	        }
	    }
	}

0