結果

問題 No.688 E869120 and Constructing Array 2
ユーザー tentententen
提出日時 2020-09-03 20:08:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 85,828 KB
実行使用メモリ 55,820 KB
最終ジャッジ日時 2024-05-03 03:21:01
合計ジャッジ時間 6,095 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
 	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int k = sc.nextInt();
    	int zero = 0;
    	int one = 0;
    	HashMap<Integer, Integer> makeOne = new HashMap<>();
    	for (int i = 2; i <= 30; i++) {
    	    makeOne.put(i * (i - 1) / 2, i);
    	}
    	for (int i = 0; i <= 28; i++) {
    	    zero = i;
    	    if (k % (1 << i) == 0) {
    	        int tmp = k / (1 << i);
    	        if (makeOne.containsKey(tmp)) {
    	            one = makeOne.get(tmp);
    	            break;
    	        }
    	    }
    	}
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < one; i++) {
    	    if (i > 0) {
    	        sb.append(" ");
    	    }
    	    sb.append(1);
    	}
    	for (int j = 0; j < zero; j++) {
    	    sb.append(" 0");
    	}
    	System.out.println(sb);
	}
}
0