結果

問題 No.688 E869120 and Constructing Array 2
ユーザー tentententen
提出日時 2020-09-03 20:10:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 1,000 ms
コード長 988 bytes
コンパイル時間 3,144 ms
コンパイル使用メモリ 74,180 KB
実行使用メモリ 57,592 KB
最終ジャッジ日時 2023-08-15 16:17:40
合計ジャッジ時間 5,873 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,912 KB
testcase_01 AC 124 ms
55,664 KB
testcase_02 AC 122 ms
55,504 KB
testcase_03 AC 121 ms
55,976 KB
testcase_04 AC 122 ms
55,416 KB
testcase_05 AC 123 ms
55,972 KB
testcase_06 AC 125 ms
55,616 KB
testcase_07 AC 122 ms
55,424 KB
testcase_08 AC 123 ms
55,896 KB
testcase_09 AC 125 ms
55,700 KB
testcase_10 AC 122 ms
57,592 KB
testcase_11 AC 123 ms
53,944 KB
testcase_12 AC 125 ms
55,632 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    	            if (one + zero <= 30) {
    	                break;
    	            }
    	        }
    	    }
    	}
    	StringBuilder sb = new StringBuilder();
    	sb.append(zero + one).append("\n");
    	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